在一个C#Windows应用程序,我用一个DataGridView来显示所有的数据。我想一个新行,当用户点击添加新行按钮添加到网格。我怎样才能做到这一点?
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?
行操纵在Windows窗体DataGridView控件:的 http://msdn.microsoft.com/en-us/library/ddtce152.aspx
Manipulate Rows in the Windows Forms DataGridView Control : http://msdn.microsoft.com/en-us/library/ddtce152.aspx
按钮的onclick添加行
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
}