473,883 Members | 2,819 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to select a row in a DataGridView on MouseDown

8 New Member

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_CellMo useDown(object sender, DataGridViewCel lMouseEventArgs e)
dgMyGrid.Rows[e.RowIndex].Selected = true;

Aug 25 '07 #1
4 12954
4,871 Recognized Expert Specialist
Is there such an event available or do you have to use a custom event handler?
Aug 26 '07 #2
8 New Member
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
8 New Member
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
1 New Member
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

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 under the mouse, but does so after a click.. Is there any way to change that behaviour in VB.NET or is there a work around? As it is now the on mousedown the previously selected item is dragged, not the one under the mouse..
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, and click on one of the rightmost cells the form scrolls to the leftmost end of the datagridview. I tried various permutations of the form's autoscroll, the datagridview's scrollbars, and the datagridview's selection mode without success. What do...
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 VerticalScrollBar { get { return base.VerticalScrollBar; } }// ScrollBar; }// ScrollDataGrid; and this...
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: DataGridView { new public ScrollBar VerticalScrollBar { get { return base.VerticalScrollBar; } }// ScrollBar; }// ScrollDataGrid;
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 to do multiple items drag and drop. Does any one know of any example of such? I only found example for one item and for 2 list controls. The problem that I'm having is when I press the shift key or control key and use the mouse to click the...
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 (like CTRL+ALT+SHIFT). TO this point I have code that only displays the context menu while keys CTRL +ALT+SHIFT are pressed - but after the keys are released the context menu still gets displayed. Can someone tell me where the following code is...
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 I should be able to just set SelectionMode to something like "NoSelect", then I could capture the MouseDown event and set Row.Selected to true when I need to. Apparently, there is no "NoSelect" option for SelectionMode. Anyone know how to do...
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 = true; When I add another entry to the datagrid, I return to this routine and check for the current row as follows: DataGridViewRow row = dataGridView2.CurrentRow;
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 the row and not anyplace within the row. Is there someway for the event to fire off regardless of where they click in the row? Here's a snippet: Private Sub dgvStuff_CellContentClick(ByVal sender As
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.