从gridview到textbox的事件与vb.net中textbox中的结果不匹配
文本框日期(txt.dte)是否为空,而不是包含上一个日期的日期,即我double of double of double cell gridview。有解决方案还是我的代码错误?
注意:我使用Visual Studio 2010
Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
x = DataGridView1.Rows.IndexOf(DataGridView1.CurrentRow)
txtCODE.Text = DataGridView1.Rows(x).Cells(0).Value.ToString()
Dim dte = DataGridView1.Rows(x).Cells(1).Value.ToString()
If dte <> Nothing Then
txtDTE.Text = CDate(dte)
End If
txtQTY.Text = DataGridView1.Rows(x).Cells(2).Value.ToString()
txtPRICE.Text = DataGridView1.Rows(x).Cells(3).Value.ToString()
End Sub
should the textbox date (txt.DTE) be empty instead of containing the date from the previous date that I did double click cell gridview. Is there a solution or is my code wrong?.
Note : I use visual studio 2010
Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
x = DataGridView1.Rows.IndexOf(DataGridView1.CurrentRow)
txtCODE.Text = DataGridView1.Rows(x).Cells(0).Value.ToString()
Dim dte = DataGridView1.Rows(x).Cells(1).Value.ToString()
If dte <> Nothing Then
txtDTE.Text = CDate(dte)
End If
txtQTY.Text = DataGridView1.Rows(x).Cells(2).Value.ToString()
txtPRICE.Text = DataGridView1.Rows(x).Cells(3).Value.ToString()
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
if
子句中添加else
代码,以便在日期列为空时清除txtDTE
的值。另一个建议:
您可以使用
e.RowIndex
而不是DataGridView1.Rows.IndexOf(DataGridView1.CurrentRow)
,它也会返回当前的行索引。示例:
代替
Add an
else
code in yourif
clause to clear the value of thetxtDTE
if the date column is blank.Another advice:
You can use
e.RowIndex
instead ofDataGridView1.Rows.IndexOf(DataGridView1.CurrentRow)
which also returns the current row index.Example:
Instead of