Page 1 of 1

How to control selected row when dataGridView created?

Posted: Tue Dec 04, 2012 3:48 pm
by Trebor29
Hi all,

I am developing a WFA to print ID cards and manage consumable orders. Order information is read from an sql server db and into a dataGridView. When the user selects a row (an order) (dataGridView1_selectionChanged event) the corresponding ID card design is pulled in and displayed in a pictureBox.

When any data is changed and the dataGridView is recreated to show the new data, it always loads with the first row selected, which ultimately displays the related ID card design. This is obviously quite confusing if the user was working on another order row...

What I need is a way to load the dataGridView with the last selected row, instead of it always being the first row!

I have used this.datagridview.Rows[0].Cells[0].selected = false, which loads the dg with an un-highlighted first row, but it still uses the first row regardless!

Any help is appreciated...... please! :!:

Re: How to control selected row when dataGridView created?

Posted: Tue Dec 04, 2012 7:06 pm
by Trebor29
UPDATE:

It appears to be something to do with the DataBinding. It is as soon as the code steps into the databind that it sets the first row selected.

I have come across a solution which uses the dataBindingComplete event and calling the .ClearSelection() from inside, but this is a solution which has not worked for me! :?