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


Author
Message
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)
And after your last reply, I looked at the ListView in Strataframe.

I suggested you to look at the StrataFlix sample application which uses the new enhanced list.

It also had no RightCLick event that I could hook in to.

A single event, the MouseClick event is used to handle all this in .NET controls like this:

Private Sub lstServiceCalls_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstServiceCalls.MouseClick

     If e.Button = Windows.Forms.MouseButtons.Right Then

          '-- do your stuff here.    

     End If

End Sub

And if all you want is to show a shortcut menu (ContextMenuStrip in .NET) all you need to do is add a SF ThemedContextMenuStrip to your form, add all the items you want then add that menu to the form's property ContextMenuStrip and you are done, not need to manage it via the right click like in VFP. 

BTW, StrataFlix Main Form also have a sample of a ThemedContextMenuStrip.

Edhy Rijo

Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Could you add a context menu to the grid?  I have done this with the DevExpress XtraGrid...works quite well.

Bill

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.

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
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.

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.
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.
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

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.

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.

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