Vb6 当我选择最后一行时,为什么在MSFlexGrid中选择了所有行?

Vb6 当我选择最后一行时,为什么在MSFlexGrid中选择了所有行?,vb6,msflexgrid,Vb6,Msflexgrid,我有一个MSFlexGrid控件,有两列,我的所有数据都显示在这个网格上。当我点击Add按钮时,我添加了一个新行,并选择了我的新行 问题是所有的行都被选中了,我只需要选择我的新行 这是我的密码: Private Sub Add_Click() FGrid.Rows = FGrid.Rows + 1 FGrid.RowSel = FGrid.Rows - 1 FGrid.ColSel = 0 If FGrid.Rows > 1 Then ' > 10

我有一个MSFlexGrid控件,有两列,我的所有数据都显示在这个网格上。当我点击Add按钮时,我添加了一个新行,并选择了我的新行

问题是所有的行都被选中了,我只需要选择我的新行

这是我的密码:

Private Sub Add_Click()
    FGrid.Rows = FGrid.Rows + 1
    FGrid.RowSel = FGrid.Rows - 1
    FGrid.ColSel = 0

    If FGrid.Rows > 1 Then ' > 10
        FGrid.TopRow = FGrid.Rows - 1
    Else
        FGrid.TopRow = 1 
    End If

    FGrid.TextMatrix(FGrid.RowSel, 0) = Format(Date, "DD/MM/YYYY")
    FGrid.SetFocus
End Sub  

看起来您正在查找的是
属性,而不是
。根据您的需求,您可以将两者结合使用

属性:

返回/设置FlexGrid中的活动单元格

RowSel
属性:

确定单元格区域的起始行或结束行或列

设置
RowSel
值时,它被视为选择的结束,因为
值仍然为0(未更改)。因此,您需要使用如下内容:

FGrid.Row = FGrid.Rows - 1
'FGrid.RowSel = FGrid.Rows - 1   ' Optional.
FGrid.AddItem Format(Date, "dd/MM/yyyy")

FGrid.Row = FGrid.Rows - 1
'FGrid.RowSel = FGrid.Rows - 1   ' Optional.
FGrid.ColSel = 0

If FGrid.Rows > 10 Then
    FGrid.TopRow = FGrid.Rows - 1
End If

FGrid.SetFocus
还有一件事,您可以使用
AddItem
添加第一个单元格中有值的行,而不是先递增
.Rows
然后使用
TextMatrix()
为单元格赋值。在本例中,您的代码如下所示:

FGrid.Row = FGrid.Rows - 1
'FGrid.RowSel = FGrid.Rows - 1   ' Optional.
FGrid.AddItem Format(Date, "dd/MM/yyyy")

FGrid.Row = FGrid.Rows - 1
'FGrid.RowSel = FGrid.Rows - 1   ' Optional.
FGrid.ColSel = 0

If FGrid.Rows > 10 Then
    FGrid.TopRow = FGrid.Rows - 1
End If

FGrid.SetFocus