在运行时在datagridview中添加行 [英] adding row in a datagridview at runtime
本文介绍了在运行时在datagridview中添加行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个datagridview,在运行时我必须在datagridview中添加行。
如何添加?
任何人都可以帮我解决这个问题。
我是vb.net的新手。我在vb.net中使用c#
解决方案
//使用ProcessCmdKey Befor Form_Load
//设置AllowUserToAdd Row为true
受保护 覆盖 < span class =code-keyword> bool ProcessCmdKey( ref 消息消息,密钥keyData)
{
if (keyData == Keys.Enter)
{
int iCol = dtg.CurrentCell.ColumnIndex ;
int iRow = dtg.CurrentCell.RowIndex;
if (iCol == dtg.Columns.Count - 1 )
{
if (iRow == dtg.Rows.Count - 1 )
{
// 基于您在DataGridView中声明的列数
dtg.Rows.Add( FirstValue, SecondValue, ......);
}
dtg.CurrentCell = dtg [ 0 ,iRow + 1 跨度>];
}
else
{
dtg.CurrentCell = dtg [iCol + 1 ,iRow];
}
返回 true ;
}
返回 base .ProcessCmdKey( ref msg,keyData);
}
我认为你在那里混淆了你的语言...你要么用C#或VB语言编写代码。 .Net部分是框架。在任何情况下,通常很容易在两者之间转换代码。
关于你的问题,试试谷歌 [ ^ ]。或此处 [ ^ ]是关于datagridview的msdn教程,可能有所帮助。
你可以尝试像 -
DataGridView1.Rows.Insert(rowPosition,New String(){value1,value2,value3 ....})
Hi All,
I have a datagridview and during runtime i have to add rows in that datagridview.
How can i add?
Can anyone help me to solve this.
I am new to vb.net. am using c# in vb.net
解决方案
// Use ProcessCmdKey Befor Form_Load
// Set AllowUserToAdd Row To true
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == Keys.Enter) { int iCol = dtg.CurrentCell.ColumnIndex; int iRow = dtg.CurrentCell.RowIndex; if (iCol == dtg.Columns.Count - 1) { if (iRow == dtg.Rows.Count - 1) { // Based On Columns Numbers That You Are Declared In DataGridView dtg.Rows.Add("FirstValue","SecondValue"," . . ."); } dtg.CurrentCell = dtg[0, iRow + 1]; } else { dtg.CurrentCell = dtg[iCol + 1, iRow]; } return true; } return base.ProcessCmdKey(ref msg, keyData); }
I think you are confusing your languages there...you are either coding in the language of C# or VB. The .Net part is the framework. In any case, it's usually pretty easy to convert code between the two.
And about your question, try google[^]. Or here[^] is an msdn tutorial on the datagridview that may help.
You could try something like -
DataGridView1.Rows.Insert(rowPosition, New String(){value1, value2, value3....})
这篇关于在运行时在datagridview中添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文