开发者

DataGridView Default Row/Cell select issue

开发者 https://www.devze.com 2023-04-11 06:21 出处:网络
DataGridView set to Full Row Select. Need a way to clear the default selected row开发者_StackOverflow thats done by the default nature of DataGridView

DataGridView set to Full Row Select. Need a way to clear the default selected row开发者_StackOverflow thats done by the default nature of DataGridView

I am also using SelectionChanged event That dgv has 4 columns

If i leave the default row selection, SelectionChanged fires 4 times when its loaded which I don't want it to fire at all.

I have tried using the RowsPostPaint event which clears the selection and doesn't fire the SelectionChanged event but i'm unable to select any rows after.

Any ideas? Thanks


To de-select the initial row selection, you can enumerate the SelectedRows and set the Selected property to false. To prevent the SelectionChanged event from firing when the initial row is selected, add the event manually, after you de-select it.

For example, in the form's Load event:

foreach(DataGridViewRow row in dataGridView1.SelectedRows)
    row.Selected = false;

dataGridView1.SelectionChanged += dataGridView1_SelectionChanged;


use this

in form loading:

     datagridview.DataBindingComplete += new DataGridViewBindingCompleteEventHandler(datagridview_DataBindingComplete);

and for the listener:

    private void datagridview_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
    {
        datagridview.ClearSelection();
    }

bute note that anytime you change datasource your default selection hides.


After populating datagrid,try this one.

datagrid.ClearSelection();

0

精彩评论

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