0

I have a datagridview that when it loaded first row is selected. I want to delete a record but I don't want first row select. I want message to user that first select a row then click delete button. I try these code but they don't worked.

//kharidDataGridView.Rows[0].Selected = false; //kharidDataGridView.ClearSelection(); //kharidDataGridView.CurrentCell = null; 

I use below codes in WPF:

object item = datagrideview1.SelectedItem; if (item == null) { //message to user } 

thank you

2
  • Execute ClearSelection after databind Commented Sep 5, 2017 at 8:23
  • Call ClearSelection() and CurrentCell = null after DataBind Commented Sep 5, 2017 at 8:25

1 Answer 1

1

You can remove default selected row by handling data-grid loaded event

private void datagrideview1_Loaded(object sender, RoutedEventArgs e) { datagrideview1.SelectedIndex = -1; } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.