0
votes

i was using datagridview in my erp but one of my new customer requested me to use devexpress

now in datagridview i was using a code as follow

  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

in line " For Each row In DataGridView1.Rows" i am not able to write this code in devexpress gridcontrol. how i can do it i mean how i can write the code somethhing like "gridview.rows"

my complete code is that i want to change for 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
1

1 Answers

0
votes

The DevExpress GridView does not have a Rows collection. You should instead loop through the rows with a for loop. See the Tutorial: Identifying Rows for more information about this. For example:

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

Use the GridView's GetRowCellValue method to retrieve the value of a cell based on the field/column name and the row index.

Use the GridView's SetRowCellValue to set the value of a cell based on the field/column name and row index.

See also: Cell Values, Editors, and Validation