开发者

datagridview rowsremoved event gets called every time data loads

The datagridview rowsremoved event gets called every t开发者_如何转开发ime the data gets loaded. It also makes sense to a certain extent that every time the data loads, the existing rows are removed. so technically the event should get called.

But how do i differenciate that from the actual delete button getting pressed. I don't think the key events should be used, that wouldn't be a clean approach.

Any help will be most appreciated.


You could use the UserDeletedRow event instead.


This is how we check to make sure the data has rows first:

If dataGridView.SelectedRows.Count > 0 Then
End If

See also: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.userdeletingrow.aspx


You could have a private boolean variable to know when you are loading and when you are not.

private bool IsLoading { get; set; }

In the form Load event, you set the variable

private void MyForm_Load(object sender, EventArgs e)
{
    this.IsLoading = true;
// do stuff
    this.IsLoading = false;
}

private void DataGridView_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
{
            if (this.IsLoading)
            {
                return;
            }

   //do stuff
}


Can you remove the event handler before loading the grid, and then re-add it afterward?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜