473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to select a row in a DataGridView on MouseDown

Hello,

This is really frustrating me. I am trying to get my application to select an entire row in my DataGridView on MouseDown. I can get it to select the whole row on MouseUp no problem, but it will not do it on MouseDown. I would think this would be extremely easy, but for some strange reason, no matter what I try, it just doesn't do it. Can anyone help me with this? Here is the code that I think should work:

private void dgMyGrid_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
dgMyGrid.Rows[e.RowIndex].Selected = true;
}


Thanks!!!
Aug 25 '07 #1
4 12771
kenobewan
4,871 Expert 4TB
Is there such an event available or do you have to use a custom event handler?
Aug 26 '07 #2
There is an event for CellMouseDown already. And the properties of e give me row index and column index and such. The event fires when the mouse button is pressed down overtop of a cell on your DataGridView (the new DataGrid). I've searched the MSDN site which gives some examples of using this event. Their example pops up a MessageBox on CellMouseDown, which tells you the column/row location of the cell you clicked. I reproduced their example, and the MessageBox does pop up on MouseDown, but regardless of what I try, the row won't select on MouseDown.
I've also tried using just the regular MouseDown even (instead of CellMouseDown), but e doesn't give you RowIndex or Column index, so that is not as useful of an event. And regardless, it doesn't work either. For either, when I do mouse down just the single cell highlights. Then if I recall correctly, on mouse up is when the whole row selects (I have since changed the events to MouseUp so I'm not sure of the prior behavior. I'm still trying to get it changed to on MouseDown/CellMouseDown though).

It's the weirdest thing. It's like their event doesn't work right.



Is there such an event available or do you have to use a custom event handler?
Aug 26 '07 #3
Grrr... I'm still hoping to figure this out. If I can't figure it out today then I'll probably just be leave it happening on the MouseUp event.
Aug 26 '07 #4
Try using the RowEnter event. Worked for me
Sep 7 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Paul van der Heu | last post by:
In an application I am writing I use both double click and mousedown, first for playing a track, second for doing a drag. Problem is that , unlike explorer, teh listview does not select the item...
0
by: Christopher Lusardi | last post by:
Hello, I have a datagridview that is too wide for the form, so I'm trying to put scrollbars on the form and the datagridview table. But, when I run the application, look at the rightmost cells,...
0
by: Rex the Strange | last post by:
How can I hook into the click event of the directional buttons of a scrollbar on the DataGridView component? I tried this: public class ScrollDataGrid: DataGridView { new public ScrollBar...
0
by: Rex the Strange | last post by:
Still looking for an answer, please: How can I hook into the click event of the directional buttons of a scrollbar on the DataGridView component? I tried this: public class ScrollDataGrid:...
0
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using vS2005 and .net 2.0. for a Windows application. I'm implementing a Drag and Drop between 2 DataGridView controls. It's working fine with just one item being drag and drop. I want...
3
by: hzgt9b | last post by:
Using VS2005, VB.NET, I am developing a windows app that has a DataGridView. I want to enable the display of a context menu on this DataGridView only when a specific set of keys is also pressed...
0
by: Dom | last post by:
I need a DataGridView in which, if the user clicks on a cell, the entire row is selected. But if the user clicks on a cell with the control-key down, the selected row does not change. I thought...
4
by: =?Utf-8?B?UGFycm90?= | last post by:
I cannot programmatically select a row in datagridview control. I use the following instruction to change the selection of a row dataGridView2.ClearSelection(); dataGridView2.Rows.Selected =...
1
by: Alex | last post by:
Hi, I need an event to fire off when someone clicks anyplace within a DataGridView row, but whether I use CellContentClick or CellClick, the event only fires off when clicking on the text within...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.