在DataGridView中添加行(带有预定义列) [英] Add Row in DataGridView ( with Predefined Columns)
问题描述
如何在winform应用程序的datagridview中添加一行。
场景是:
- 我在Windows窗体上有一个网格。
- 网格的列是预先定义的。 (这里,我的意思是列索引,名称,标题文本和顺序在运行时不可更改。)
- 我需要在该网格中添加新行。
任何人,在这方面帮助我。我该怎么做这个任务?
How to add a row in datagridview in winform application.
Scenario is:
- I've one grid on windows form.
- Grid's columns are pre-definded. (Here, I mean column index, name , header text and order is not changeable at runtime.)
- I need to add new row in that grid.
Anyone, help me in this regard. How can I do this task ?
推荐答案
试试这个:
Try this:
private void InsertNewRowToDGV()
{
//we have to get the index of a last row id:
int index = this.dataGridView1.Rows.Count;
//and count +1 to get a new row id:
index++;
this.dataGridView1.Rows.Add();
}
参考更多详情:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rowsadded.aspx [<一个href =http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rowsadded.aspxtarget =_ blanktitle =New Window> ^ ]
http://msdn.microsoft.com/en-us/library/5s3ce6k8 .aspx [ ^ ]
请在下面给出此代码
将空白行添加到数据网格视图中
Please this code given bellow
to add blank row into the data grid view
DataGridView.Rows.Add()
。
.
Or Can you use this coding also
Suppose I have a DataGridView having three columns named ItemName,Itemcode and ItemQuantity
for that you can use following code given bellow
DataGridView.Rows.Add("ItemName","ItemCode","Quantity",)
这篇关于在DataGridView中添加行(带有预定义列)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!