DataGridView1选择其中一行后,点旁边按钮打开新窗体修改数据,如何做
点击按钮后如何把这行数据的ID号传到新窗体中啊,新窗体通过id查询数据进行修改数据,
[解决办法]
亲:看看这个例子吧http://blog.csdn.net/wlccomeon/article/details/9100447
[解决办法]
是C#代码,有空帮你修改为vb.net ,
选择的ID给txtFind.Text ,再通过查询到相应的行
int row = dataGridView1.Rows.Count;//得到总行数
int cell=dataGridView1.Rows[1].Cells.Count;//得到总列数
for (int i = 0; i < row; i++)//得到总行数并在之内循环
{
for (int j = 0; j < cell; j++)//得到总列数并在之内循环
{
if (txtFind.Text == dataGridView1.Rows[i].Cells[j].Value.ToString())
{ //对比TexBox中的值是否与dataGridView中的值相同(上面这句)
this.dataGridView1.CurrentCell = this.dataGridView1[j, i];//定位到相同的单元格
return;//返回
}
}
}
form1中
Public Shared s1 As String ’用于传递参数
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s = DataGridView1.SelectedCells(0).Value.ToString()
s1 = s
Dim f2 As Form2 = New Form2()
f2.ShowDialog(Me)
End Sub
form2中
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = Form1.s1.ToString()’接收form1中的数
End Sub
'根据文本框的ID,在DataGridView1中找到相应的行,进行编辑
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim row As Integer = DataGridView1.Rows.Count '得到总行数
Dim cel As Integer = DataGridView1.Rows(1).Cells.Count '得到总列数
Dim i As Integer
For i = 0 To row - 1 '//得到总行数并在之内循环
For j As Integer = 0 To cel - 1 '//得到总列数并在之内循环
If TextBox1.Text = DataGridView1.Rows(i).Cells(j).Value.ToString() Then
'对比TexBox中的值是否与dataGridView中的值相同(上面这句)
DataGridView1.CurrentCell = DataGridView1(j, i) '定位到相同的单元格
Return '//返回
End If
Next j
Next i
End Sub