Question

I am trying to get the value of a certain column in a datagrid for comparison. I try to find and read the properties of DataGrid from MSDN website, but I didn't manage to find it. (maybe it's because I am lack of knowledge)

Private Sub DataGridView2_SelectionChanged(sender As Object, e As EventArgs) Handles DataGridView2.SelectionChanged

        Dim id As String = Me.DataGridView2.SelectedRows(0).Cells(0).Value.ToString
        If grdList.X.ID = label Then
            CurrentRowIndex = Me.DataGridView2.CurrentRow.Index
        End If

    End Sub

My problem is I don't know what to write to replace the X here. "ID" is one of the column in the DataGrid, like other columns "Name", "Date", "Version". grdList is my DataGrid here. I have set CurrentRowIndex full property so that it can be used again later.

When a button "Edit" is clicked, the following steps will be carried out.

Public Overrides Sub edit(ByVal restoreControlValues As Boolean)
        'Für ITDB-extra-Anpassung -> Irgendwann ITDB korrigieren
        If Me.ToString.Contains("IMF.ITDB.frmDataPCSelList") Then
            If grdList.CurrentRowIndex >= 0 Then
                MyBase.edit(restoreControlValues)
            End If
            Exit Sub
        End If
        grdList.CurrentRowIndex = CurrentRowIndex
        If grdList.CurrentRowIndex >= 0 Then MyBase.edit(False)
    End Sub

The comparison is to compare a certain identity of the whole row (eg. ID or Name), then can confirm the current index and to pass all the informations (ID, Name, Data, Version) into the dialog with textboxes open by that "Edit" button.

I will be very greatful if you can give me your ideas and guides. Thank you in advance.

Was it helpful?

Solution

I just got solution for this. Actually I was thinking so much, and the answer just simply like this:

grdList(i, j)

where i is the number or row and j is the number of column.

Let say my "ID" is on second column, then I just need to write the grdList(i, 1)

And then I do a for-loop for i to compare all the value of "ID"-column.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top