473,324 Members | 2,254 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,324 software developers and data experts.

Datagridview cell position (.Net 2008).

88 64KB
How can I get the position of a certain cell of a datagridview. To be specific I don't want the mouse coordinates. Suppose I have a datagridview with Name (ReadOnly), ID and TransDate columns and I want to popup a tiny lookup form when the mouse is clicked or Enter button is pressed when the focus is upon the Name column. The lookup form should openup exactly upon the Name column of the selected row. Thanks.
Mar 30 '10 #1
2 2013
priyamtheone
88 64KB
Here's a solution I came up to.
I am opening a dialog form above the datagridview form. In Form1 I have a datagridview containing few columns among which is 'TransDate' column having index 8. When I click on it, frmDate opens up exactly on it. My revised code follows:


Expand|Select|Wrap|Line Numbers
  1. Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridview1.CellClick
  2.     If DataGridview1.CurrentCell.OwningColumn.Name = "TransDate" Then
  3.         Dim objPoint As Point
  4.  
  5.         'Getting the exact location of the cell with respect to Form1.
  6.         'Note- Me.Location is added here alongwith DataGridView1.Location and DataGridView1.GetDisplayRectangle().Location.
  7.         'This is done because the form frmDate we are calling is external to Form1 and if we don't add Me.Location
  8.         'here, frmDate won't open exactly at the desired point if we move or resize Form1. Instead of frmDate if
  9.         'we use any control inside Form1 to place over 'TransDate' column then remove Me.Location here and the
  10.         'next two lines.
  11.         objPoint = (Me.Location + DataGridview1.Location + DataGridview1.GetCellDisplayRectangle(8, DataGridview1.CurrentCellAddress.Y, True).Location)
  12.  
  13.         'Setting the exact location where frmDate will be opened. The last digits may vary according to your
  14.         'requirement.
  15.         objPoint.X = objPoint.X - 158
  16.         objPoint.Y = objPoint.Y + 28
  17.  
  18.         objFrmDate = New frmDate()
  19.         objFrmDate.Location = objPoint
  20.         objFrmDate.ShowDialog(Me)
  21.         objFrmDate = Nothing
  22.     End If
  23. End Sub
Regards.
Apr 15 '10 #2
MrMancunian
569 Expert 512MB
You can use the DataGridViewCellMouseEventArgs to get the RowIndex and the ColumnIndex. Check out this MSDN page.

Steven
Apr 19 '10 #3

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

Similar topics

5
by: Peter | last post by:
How do I get DataGridViewCell cell position in a window? For a button I would do this: this.Button.PointToClient(this.Button.Location) But what do I do for DataGridViewCell? Thanks
0
by: Steve | last post by:
I am looking for an example of a custom user control ( 2 labels and 2 datetime pickers ) in a datagridview cell. Every example I have come across handles only once control such as a datetimepicker...
11
by: dgk | last post by:
Is there a way to change the foreground or background color of a single cell in an unbound datagridview?
3
by: Rich | last post by:
Hello, If I want to update data displayed in a datagrideview/datagridview cell, how can I determine what cell I am updating? I am looking at the click event below, for example. Can I get...
0
by: Bob | last post by:
Hi Trying to overlay a Datagridview current cell with a dtp so that the client gets to set the current cell value via the dtp. Figured Start with dtp at the back then bring it to the front when...
0
by: varunk2 | last post by:
Hi How to autocomplete a datagridview cell in c# windows forms. Please anybody help me... Thanks in advance Regards,
0
by: hydro123 | last post by:
I am using VC++2008 and am trying to read data enetered in unbound datagridview to implement in function. Under button_click event I entered the following: // initialize varaibles from...
0
by: ziketo | last post by:
Hi, I searched a lot about changing the DataGridView cell borders. BYTES helped me so I will write down the solution: 1. You should override the class DataGridViewTextBoxCell, and the new class...
0
by: priyamtheone | last post by:
Problem in ToolStripButton (.Net 2008, Framework 3.5). Hi, I have an editable datagridview that's been databound with dataadapter and datatable, and a normal button on a form. When i edit the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.