[RESOLVED] Create table in Windows.Forms?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: [RESOLVED] Create table in Windows.Forms?

  1. #1
    Join Date
    Jan 2010
    Posts
    130

    [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?

  2. #2
    Join Date
    Apr 2010
    Posts
    131

    Re: Create table in Windows.Forms?

    DataGridView
    DataGridView.Rows.Add();
    DataGridView.Rows[].SetValues();

    Cheers!

  3. #3
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,537

    Re: Create table in Windows.Forms?

    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

  4. #4
    Join Date
    Apr 2010
    Posts
    131

    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!

  5. #5
    Join Date
    Jan 2010
    Posts
    130

    Re: Create table in Windows.Forms?

    Thank you, Ill try that
    Last edited by stephsh; May 28th, 2010 at 04:35 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center