Vitual Mode in DGV

  • Thread starter Thread starter glaeran
  • Start date Start date
G

glaeran

Guest
Dear MSDN,

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

Around whole program I have around 10 DGV (and the number is increasing lets say 1/month). Thats 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 Im not sure if in my case [with dynamic ammount of columns and one class to populate every DGV] its possible to do using it.

Any ideas how it might be solved?

Continue reading...
 
Back
Top