Technology Programming

How to Update Grid Data

    • 1). Open Microsoft Visual C# Express and select "New Project..." from the left pane of your screen. Click "Visual C#" under "Installed Templates" and double-click "Windows Forms Application."

    • 2). Click the "Toolbox" pane and double-click "DataGridView" to add a new Grid control. Double-click "Button" to add a new button to your Form.

    • 3). Double-click on the Form to open "Form1_Load" and type the following below "Form1_Load":

      dataGridView1.ColumnCount = 3;

      dataGridView1.Columns[0].Name = "F0";

      dataGridView1.Columns[1].Name = "F1";

      dataGridView1.Columns[2].Name = "F2";

      string[] r0 = { "0,0", "0,1", "0,2" };

      string[] r1 = { "0,0", "0,1", "0,2" };

      string[] r2 = { "0,0", "0,1", "0,2" };

      dataGridView1.Rows.Add(r0);

      dataGridView1.Rows.Add(r1);

      dataGridView1.Rows.Add(r2);

      This code is used to load the Data Grid View control with some data.

    • 4). Click the "Form1.cs [Design]" tab and double-click "button1" to open the "Form1.cs" window. Type the following code below under "button1_Click":

      dataGridView1.Rows[1].Cells[0].Value = "Updated programmatically!";

      This code is used to update the first cell in the second row of the Data Grid View control.

    • 5). Press "F5" to run the program, then click "button1" to update.



Leave a reply