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?
Is the grid filled by the DataTable from a Database ?
Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ? My latest articles : Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
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.
Bookmarks