In a C# Windows application, I'm using a DataGridView to display all the data. I want to add a new row to the grid when the user clicks the Add New Row button. How can I accomplish this?
A:
In your onclick event, are you calling DataTable.Rows.Add() or similar?
voltagex
2010-07-01 06:37:42
+1
A:
Manipulate Rows in the Windows Forms DataGridView Control : http://msdn.microsoft.com/en-us/library/ddtce152.aspx
onclick of button add row by using dataGridView.Rows.Add as shown below in example
// Populate the rows.
string[] row1 = new string[]{"Meatloaf",
"Main Dish", boringMeatloaf, boringMeatloafRanking};
string[] row2 = new string[]{"Key Lime Pie",
"Dessert", "lime juice, evaporated milk", "****"};
string[] row3 = new string[]{"Orange-Salsa Pork Chops",
"Main Dish", "pork chops, salsa, orange juice", "****"};
string[] row4 = new string[]{"Black Bean and Rice Salad",
"Salad", "black beans, brown rice", "****"};
string[] row5 = new string[]{"Chocolate Cheesecake",
"Dessert", "cream cheese", "***"};
string[] row6 = new string[]{"Black Bean Dip", "Appetizer",
"black beans, sour cream", "***"};
object[] rows = new object[] { row1, row2, row3, row4, row5, row6 };
foreach (string[] rowArray in rows)
{
dataGridView.Rows.Add(rowArray); // addding row
}
Pranay Rana
2010-07-01 06:41:09
ya fine thank you
Lawrance Rozario
2010-07-01 12:01:02