Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Vitual Mode in DGV

$
0
0

Dear MSDN,

I do realise that probably there are tons of topic about VM in DGV, however still I'm having problems with changing mine code into the "proper" one.

Around whole program I have around 10 DGV (and the number is increasing let's say 1/month). That's why I would like to create 1 single class to populate all DGVs, but with different queries which later on would be shown in correct WinForm.

How it is now:

        private DataTable PopulateDGV()
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["ERS"].ConnectionString;
            string query = "SELECT guid,DataWydaniaZgody,NrUmowy,Handlowiec,odstepstwoTF,odstepstwoGAP,odstepstwoHL,odstepstwoSL,odstepstwoWC,odstepstwoTA,KtoWydalZgode,koszykevo,Uwagi FROM ERS_AGGREGATES.ria.RIA_OdstepstwaProdDod ORDER BY DataWydaniaZgody";
            SqlDataAdapter dataAdapter = new SqlDataAdapter(query, conn);
            SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
            DataTable table = new DataTable();
            table.Locale = System.Globalization.CultureInfo.InvariantCulture;
            dataAdapter.Fill(table);
            dataGridView1.DataSource = table;
            dataGridView1.Columns["guid"].Visible = false;
            return table;
        }

How I see it?

Class1:

public string Query;

public DataTable/List<>(?) PopulateDGV()
{
// here goes the whole code without defining Query
}

Form:

private void MenuOdstępstwa_Load(object sender, EventArgs e)
        {
            Class1.Query = 'SELECT.....';
            Class1.PopulateDGV();
            if (dataGridView1.RowCount > 0)
            {
                dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.RowCount - 1;
            }
        }

All VM I saw was implemented using List. However I'm not sure if in my case [with dynamic ammount of columns and one class to populate every DGV] it's possible to do using it.

Any ideas how it might be solved?


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>