从gridview到textbox的事件与vb.net中textbox中的结果不匹配

发布于 2025-01-19 03:57:23 字数 943 浏览 3 评论 0原文

文本框日期(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

”查看gridview“

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

view gridview

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

微暖i 2025-01-26 03:57:23

if 子句中添加 else 代码,以便在日期列为空时清除 txtDTE 的值。

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)
        else
            ' CLEAR txtDTE if dt = nothing
            txtDTE.clear()
        End If
        txtQTY.Text = DataGridView1.Rows(x).Cells(2).Value.ToString()
        txtPRICE.Text = DataGridView1.Rows(x).Cells(3).Value.ToString()
    End Sub

另一个建议
您可以使用 e.RowIndex 而不是 DataGridView1.Rows.IndexOf(DataGridView1.CurrentRow) ,它也会返回当前的行索引。

示例:

x = e.RowIndex()

代替

x = DataGridView1.Rows.IndexOf(DataGridView1.CurrentRow)

Add an else code in your if clause to clear the value of the txtDTE if the date column is blank.

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)
        else
            ' CLEAR txtDTE if dt = nothing
            txtDTE.clear()
        End If
        txtQTY.Text = DataGridView1.Rows(x).Cells(2).Value.ToString()
        txtPRICE.Text = DataGridView1.Rows(x).Cells(3).Value.ToString()
    End Sub

Another advice:
You can use e.RowIndex instead of DataGridView1.Rows.IndexOf(DataGridView1.CurrentRow) which also returns the current row index.

Example:

x = e.RowIndex()

Instead of

x = DataGridView1.Rows.IndexOf(DataGridView1.CurrentRow)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文