Is there any way to change the selected row in a DataGridView programmatically?


Author
Message
Marcia G Akins
Marcia G Akins
StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)
Group: StrataFrame Users
Posts: 322, Visits: 529
Hi All.

The reason that I want to do this is necause I am using a context menu to allow them to add, edit and delete item (it calls up a modal dialog). It is a little confusing to them if they right click, select edit or delete, and the information from a different row shows up in the modal dialog.

TIA

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Marcia,

I believe you are using a datagrid to display the data.  If you don't need to modify the data in the grid and will use a modal form, I strongly suggest you use a ListView, this control have been greatly enhanced to support this type of presentation to the end user and it is pretty easy to setup, the StrataFlix Movie form (I believe that is the name) make use of this so you can examine and start using right away.

When I first started with SF and coming from VFP I tried to use a datagrid, but if the data in the grid/listview will be readonly, then nothing beats the listview enhancements in version 1.6.6.

Edhy Rijo

Dustin Taylor
Dustin Taylor
StrataFrame Team Member (652 reputation)
Group: StrataFrame Users
Posts: 364, Visits: 771
Yep, 100% agree with Edhy on this one. The listview can't be beat in most situations. There are still those areas where you need a grid, but you'd be surprised how robust a listview can be while still keeping the interface and design fairly simple.

To answer your question, however, you can use the Navigate, Move, or Seek methods of the business object to change the CurrentRowIndex of the business object. Navigate will update any bound controls to reflect the new CurrentRowIndex, while Move and Seek move the CurrentRowIndex pointer without updating any bound controls.

So for your grid, on a right click you could do a SeekToPrimaryKey(primaryKeyOfClickedRow) to move the CurrentRowIndex of your BO before doing the edit or delete.

Marcia G Akins
Marcia G Akins
StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)
Group: StrataFrame Users
Posts: 322, Visits: 529
Edhy Rijo (09/05/2008)
Hi Marcia,

When I first started with SF and coming from VFP I tried to use a datagrid, but if the data in the grid/listview will be readonly, then nothing beats the listview enhancements in version 1.6.6.

Since I practically have this working the way I want, I will take that advice in the future and refactor this form after I have enoough cranked out to show the client at our next meeting Smile

Thanks for the advice.

Marcia G Akins
Marcia G Akins
StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)
Group: StrataFrame Users
Posts: 322, Visits: 529
Dustin Taylor (09/05/2008)

So for your grid, on a right click you could do a SeekToPrimaryKey(primaryKeyOfClickedRow) to move the CurrentRowIndex of your BO before doing the edit or delete.

Color me stupid, but I do not see any RightClick event in the DataGridView that I can handle Unsure

If you can tell me where it is, I would be happy to hook into it Smile

StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
It's probably called MouseClick or PreviewMouseClick.  The event args will tell you which button(s) was clicked to raise the event.
StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Yep, MouseClick is the general one.  There's also a bunch of Mouse* methods like MouseDown and MouseUp you can handle.  Also, the grid has CellClick and CellDoubleClick, and ones like ColumnHeaderMouseClick and ColumnHeaderMouseDoubleClick.  Almost all of those will have MouseEventArgs which will tell you the mouse button that was used.  Just test on e.Button == MouseButtons.Right or something like that in your handler and you should be in business.
Marcia G Akins
Marcia G Akins
StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)
Group: StrataFrame Users
Posts: 322, Visits: 529
Ben Chase (09/05/2008)
It's probably called MouseClick or PreviewMouseClick.  The event args will tell you which button(s) was clicked to raise the event.

Yes. I found that event. What I couldn't find was a way to set the SelectedRow in the grid.

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Marcia G Akins (09/05/2008)
Yes. I found that event. What I couldn't find was a way to set the SelectedRow in the grid.

The time and effort you are putting on the grid is good for learning, but taking a 10 minute look at the listview in StrataFlix will give you all the things you are trying to do manually and much more. 

Trust me I've been there, and did the same thing until I understood that the SF listview is not like the one in VFP which I hardly used. Tongue

Edhy Rijo

Marcia G Akins
Marcia G Akins
StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)
Group: StrataFrame Users
Posts: 322, Visits: 529
Edhy Rijo (09/05/2008)
Marcia G Akins (09/05/2008)
Yes. I found that event. What I couldn't find was a way to set the SelectedRow in the grid.

The time and effort you are putting on the grid is good for learning, but taking a 10 minute look at the listview in StrataFlix will give you all the things you are trying to do manually and much more. 

Trust me I've been there, and did the same thing until I understood that the SF listview is not like the one in VFP which I hardly used. Tongue

I used the listview quite a bit in VFP Smile

And after your last reply, I looked at the ListView in Strataframe.

It also had no RightCLick event that I could hook in to. I will re-visite this issue after my meeting with the client Smile

I truely appreciate all of the help you ave given me.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search