как прочитать номер строки datagridview

#vb.net

#vb.net

Вопрос:

я использую этот код, чтобы добавить имя в datagridview в столбцы 1

 Dim scAutoComplete As AutoCompleteStringCollection
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        scAutoComplete = New AutoCompleteStringCollection

        If con.State = ConnectionState.Closed Then con.Open()
        Dim cmd As SqlCeCommand
        cmd = New SqlCeCommand("Select id ,name from tab_name", con)
        Dim dr = cmd.ExecuteReader()
        While dr.Read
            scAutoComplete.Add(dr(1))
        End While
    End Sub

  Private Sub DataGridView_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DGV.EditingControlShowing
        Dim ItemCode As TextBox = TryCast(e.Control, TextBox)
        If ItemCode IsNot Nothing Then
            If DGV.CurrentCell.ColumnIndex = 1 Then
                ItemCode.AutoCompleteMode = AutoCompleteMode.SuggestAppend
                ItemCode.AutoCompleteCustomSource = scAutoComplete
                ItemCode.AutoCompleteSource = AutoCompleteSource.CustomSource
            Else
                ItemCode.AutoCompleteMode = AutoCompleteMode.None
            End If

        End If

    End Sub
 

Я хочу прочитать номер строки, добавить идентификатор в столбцы (0)

Ответ №1:

Вы должны иметь возможность использовать DataGridView.CurrentCellAddress для получения строки