首页 > 解决方案 > DATAGRIDVIEW 和 DEVEXPRESS 的 GRIDVIEW

问题描述

我在我的 erp 中使用 datagridview,但我的一位新客户要求我使用 devexpress

现在在datagridview我使用的代码如下

  Dim items As Boolean = False
        For Each row In DataGridView1.Rows
            If TextBox1.Text = row.Cells("Barcode").Value Then
                items = True
                Exit For
            End If
        Next

在“对于 DataGridView1.Rows 中的每一行”行中,我无法在 devexpress gridcontrol 中编写此代码。我该怎么做我的意思是我怎么能写出像“gridview.rows”这样的代码

我的完整代码是我想更改 DEVEXPRESS --- GRIDVIEW

  If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then

        Dim items As Boolean = False

        ' For Each row In DATAGRIDVIEW.ROW

                     If DebitaccountTextEdit.Text = row.Cells("Barcode").Value Then


                items = True
                Exit For
            End If
        Next

        If items = False Then
            DataGridView1.Rows.Add(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text)

            MessageBox.Show(Me, "Item Added to List", "System Information", MessageBoxButtons.OK, MessageBoxIcon.Information)


            TextBox1.Clear()
            TextBox2.Clear()
            TextBox3.Clear()
            TextBox4.Clear()
            TextBox5.Clear()
            TextBox6.Clear()

        Else
            MessageBox.Show(Me, "Item Already Added", "System Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End If
    End If

标签: devexpressvb.net-2010

解决方案


DevExpress GridView 没有 Rows 集合。您应该使用 for 循环遍历行。有关这方面的更多信息,请参阅教程:识别行。例如:

for (int i = 0; i < gridView1.RowCount; i++)
{
     object barCodeValue = gridView1.GetRowCellValue(i, "Barcode");
}

使用 GridView 的GetRowCellValue方法根据字段/列名称和行索引检索单元格的值。

使用 GridView 的SetRowCellValue根据字段/列名称和行索引设置单元格的值。

另请参阅:单元格值、编辑器和验证


推荐阅读