简体   繁体   English

获取Datagridview的价值

[英]Getting Datagridview value

Using VB.Net, 使用VB.Net,

In my application, am using datagridview, when i clicking the particular row, that rows value should be appear in the textbox. 在我的应用程序中,使用datagridview时,当我单击特定行时,该行值应出现在文本框中。

So the code should be come under the DataGrid3_CellMouseDoubleClick Event. 因此,代码应位于DataGrid3_CellMouseDoubleClick事件下。

How to dispaly a rows value in the textbox. 如何在文本框中显示行值。

For Example 例如

3 rows means - 3 rows values should display in 3 textbox. 3行表示-3行值应显示在3个文本框中。

vb6 code vb6代码

Private Sub datagrid1_DblClick()

    textbox1 = datagrid1.SelectedItem.SubItems(1)
    textbox2 = datagrid1.SelectedItem.SubItems(2)
    textbox3 = datagrid1.SelectedItem.SubItems(3)
End Sub

How to write a code in vb.net by getting datagrid row values. 如何通过获取datagrid行值在vb.net中编写代码。

Need VB.Net sample code Help 需要VB.Net示例代码帮助

Try this -> 试试这个->

Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim i As Integer
i = DataGridView1.CurrentRow.Index
TextBox1.Text = DataGridView1.Item(0, i).Value
TextBox2.Text = DataGridView1.Item(1, i).Value
TextBox3.Text = DataGridView1.Item(2, i).Value
TextBox4.Text = DataGridView1.Item(3, i).Value
End Sub

Here i is the RowIndex of the selected row for DataGridView1.Item(0, i), and the number is the cell index. 在这里,i是DataGridView1.Item(0, i),所选行的RowIndex,数字是单元格索引。

You will have to loop through the rows and cells of your datagridview in order to get the values. 您将不得不遍历datagridview的行和单元格以获得值。

Something like this: 像这样:

if (datagrid1.SelectedRows.Count > 0)
{
     for (int i = 0; i < datagrid1.SelectedRows.Count; i++)
     {
          DataGridViewRow gridRow = datagrid1.SelectedRows[i];
          textbox1 = gridRow.Cells[0].Value;
          textbox2 = gridRow.Cells[1].Value;
          textbox3 = gridRow.Cells[2].Value;
     }
}

I assume you want the selected rows only. 我假设您只想要选定的行。 If not should be easy to just loop through all of them. 如果不是这样,那么很容易遍历所有这些对象。 Also I am not sure how to convert it to VB.NET but am sure you can see what I am trying to do. 另外,我不确定如何将其转换为VB.NET,但可以确保您可以看到我正在尝试做的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM