我在datagrid中选中了一行,选中一行的事件是什么,是DataGrid1_RowColChange吗?
我想获得这一行的某一列的内容。
比如我想获得第一列的值是8,第二列的值是剑圣。
我不知道该怎么写代码。请大家帮下忙。

解决方案 »

  1.   


    'VB6 datagrid单击单元格,返回单元格的值.Private Sub DataGrid1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) 
        Dim RowValue, ColValue 
        RowValue = DataGrid1.RowContaining(Y) 
        ColValue = DataGrid1.ColContaining(X) 
        
        If RowValue >= 0 And RowValue <= DataGrid1.VisibleRows And _ 
            ColValue >= 0 And ColValue <= DataGrid1.VisibleCols Then 
            DataGrid1.Row = RowValue 
            MsgBox DataGrid1.Columns(ColValue).Value ' 
      End If 
    End Sub----------------------------------------------------------------Private Sub DataGrid1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Dim RowValue, ColValue
        RowValue = DataGrid1.RowContaining(Y)
        ColValue = DataGrid1.ColContaining(X)
        
        If RowValue >= 0 And RowValue <= DataGrid1.VisibleRows And _
            ColValue >= 0 And ColValue <= DataGrid1.Columns.Count Then
            DataGrid1.Row = RowValue
            Text1.Text = DataGrid1.Columns(ColValue) '
        End If
    End Sub
      

  2.   


    Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
       MsgBox DataGrid1.Columns(0) & " " & DataGrid1.Columns(1)
       
    End Sub
      

  3.   

    Private Sub DataGrid1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Dim rowValue, colmValue
        rowValue = DataGrid1.RowContaining(Y)
        colmValue = DataGrid1.ColContaining(X)
        DataGrid1.Row = rowValue
        Label1.Caption = DataGrid1.Columns(colmValue).Text