CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #3
    Join Date
    Mar 2006
    Posts
    38

    Re: Inserting a new row in datagridview

    I think you should create a table then
    create the desired columns and associated it with the table then add the row for example like the below code
    Code:
    //add a datagridview to your code -> dataGridView1
     
    DataTable tabel;
                    DataColumn nameColmn;
                    DataColumn mobileNoColmn;
                    DataColumn homeNoCol;
                    DataColumn workNoCol;
                    DataColumn emailColmn;
    
    tabel = new DataTable();
                nameColmn = tabel.Columns.Add("Name");
                homeNoCol = tabel.Columns.Add("Home");
                mobileNoColmn = tabel.Columns.Add("Mobile");
                workNoCol = tabel.Columns.Add("Work");
                emailColmn = tabel.Columns.Add("Email");
         
    //associate the tabel with datagrid view       
         dataGridView1.DataSource = tabel.DefaultView;
    
    create the row to add
    
    DataRow row = tabel.NewRow();
                            row[nameColmn] = "Falco Eyes";
                            row[homeNoCol] = "123456";
                            row[mobileNoColmn] = "";
                            row[workNoCol] = "";
                            row[emailColmn] = "[email protected]";
                            tabel.Rows.Add(row);
    Last edited by HanneSThEGreaT; May 13th, 2009 at 01:37 AM.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured