[RESOLVED] Create table in Windows.Forms?
I would like to create a simple quick dynamic table in my Windows.Form consisting of three fixed columns and rows that are added at run-time. I have tried working with DataSets and TableLayout but I dont understand how I can add rows dynamically and I couldnt get my head around it! What is the best method to use and could you give an example of how I can do this please?
Re: Create table in Windows.Forms?
DataGridView
DataGridView.Rows.Add();
DataGridView.Rows[].SetValues();
Cheers!
Re: Create table in Windows.Forms?
Is the grid filled by the DataTable from a Database ?
Re: Create table in Windows.Forms?
You can databind the control if you want. The last two methods I provided as examples are for dynamic entry.
dg.Rows.add() adds as many rows as you would like, and
dg.Rows[].SetValues places an array of values into a row
DataGridView dg = new DataGridView();//or create one visually in VS
this.Controls.Add(dg);
dg.Rows.Add(1);
dg.Rows[0].SetValues(new string[] {"Col1Value","Col2Value","Col3Value"});
You can also reference individual cells using dg[col,row] like dg[0,0].Value = "FirstRowFirstColumn");
google my earlier examples for more info and let me know if you have any questions.
Cheers!
Re: Create table in Windows.Forms?
Thank you, Ill try that :)