1

我有一个DataGridView我正在以编程方式添加行。

通常,当我添加第一行数据时,SelectionChanged事件会触发

但是我的 Grid 锚定在表单的顶部和底部,当我使表单变小以使 Grid 的高度为零SelectionChanged时,添加第一行时不会触发事件。

这是设计使然吗?这对我来说似乎不合逻辑。

    With DataGridView1
        .Rows.Clear()
        .Columns.Clear()
        .Columns.Add("Col1", "Col1")
        .Columns.Add("Col2", "Col2")
        'uncomment the following line and the SelectionChanged event does not fire
        '.Height = 0
        .Rows.Add("foo", "bar")
    End With
4

1 回答 1

0

每次选择未选择的行时都会触发此事件,无论网格不可见还是其高度为零

When a row is selected and you try to select it again at that time event not fired If you need to fire every time this event than first unselect that row and than select the same row in the case this event occure 2 time 1st for unselect and第二行选择

dataGridView2.Rows[index].Selected = false;
dataGridView2.Rows[index].Selected = true;
于 2012-04-19T10:48:01.450 回答