How to control selected row when dataGridView created?

Topics on common programming languages
Post Reply
User avatar
Trebor29
Lieutenant
Lieutenant
Posts: 75
Joined: Thu Apr 29, 2010 12:34 am

How to control selected row when dataGridView created?

Post by Trebor29 » Tue Dec 04, 2012 3:48 pm

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! :!:
User avatar
Trebor29
Lieutenant
Lieutenant
Posts: 75
Joined: Thu Apr 29, 2010 12:34 am

Re: How to control selected row when dataGridView created?

Post by Trebor29 » Tue Dec 04, 2012 7:06 pm

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! :?
Post Reply

Return to “.Net & Other Programming”