473,465 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

.HitTestInfo Class

5 New Member
I'm trying to give a context menu to my user when they right click on a particular row in my datagrid. I created two functions that pass back the indicies for the row and column. The following code is located in the Mouse_Clicked event point for the datagrid itself. When I right click the first time everything works perfetly, but the next time I right click the context menu comes up but nothing else gets updated. If I left click on the datagrid then right click it behaves normally, so I guess my question is why doesn't the mouse_click event fire correctly when the user right clicks? Here is the code:


Expand|Select|Wrap|Line Numbers
  1.     Private Sub dgridContractors_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgridContractors.MouseClick
  2.         If e.Button = Windows.Forms.MouseButtons.Right Then
  3.             'Hightlight the row
  4.             Me.dgridContractors.Rows(dgridContractors.CurrentRow.Index).Selected = False
  5.             Me.dgridContractors.Rows(NewRowIndex(e.X, e.Y)).Selected = True
  6.  
  7.             With Me.ContextMenuStrip1
  8.                 .Items.Clear()
  9.                 .Items.Add("Delete this record")
  10.                 .Items.Add("Sort by Column """ & dgridContractors.Columns(NewColumnIndex(e.X, e.Y)).HeaderText & """")
  11.             End With
  12.             ContextMenuStrip1.Show(Windows.Forms.Cursor.Position)
  13.         End If
  14.     End Sub
  15.  
  16.     Private Function NewRowIndex(ByVal x As Integer, ByVal y As Integer) As Integer
  17.         Dim info As DataGridView.HitTestInfo = dgridContractors.HitTest(x, y)
  18.         Return info.RowIndex
  19.         info = Nothing
  20.     End Function
  21.  
  22.     Private Function NewColumnIndex(ByVal x As Integer, ByVal y As Integer) As Integer
  23.         Dim info As DataGridView.HitTestInfo = dgridContractors.HitTest(x, y)
  24.         Return info.ColumnIndex
  25.         info = Nothing
  26.     End Function
  27.  
Apr 11 '08 #1
0 963

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

Similar topics

2
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A,...
1
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
1
by: GG | last post by:
Is there a class similar to DataGrid.HitTestInfo for Keyboard moving? Need to get the coordinates of the grid when the user is using the shift key and arrows Thanks *** Sent via...
2
by: Tom P | last post by:
I'm trying to use DataGrid.HitTestInfo in my OnMouseDown event but firstly I cannot see it in Intellisense, secondly when I try to use it I get strange 'COMPILE' errors when building the app I'll...
5
by: Andy | last post by:
Hi all, I have a site with the following architecture: Common.Web.dll - Contains a CommonPageBase class which inherits System.Web.UI.Page myadd.dll - Contains PageBase which inherits...
3
by: Gene Hubert | last post by:
I'm using DataTable.ImportRow to move data from one datatable to another... Dim dt, dtTarget As DataTable Dim dr As DataRow dt = DirectCast(Me.DataSource, DataTable) dtTarget = dt.Clone...
15
by: Brett Romero | last post by:
I've read on the forums of other people having problems with HitTestInfo not appearing. I've read these but they didn't help: ...
1
by: asprabahar | last post by:
Hi I have a Different Issue the Class DataGrid.HitTestInfo is missing . The issue is when i type DataGrid and then when i type (.) and the HitTestInfo is not diaplaying ,but the say way when i copy...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
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...
0
tracyyun
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...
0
agi2029
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,...
0
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...
0
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 ...

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.