473,563 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get CurrentCell location in DataGridView?

I can find the X and Y (column/row) coordinates, but not the actual location
(Left,Top) positions.

Any ideas?

Lennart
Feb 7 '07 #1
5 32592
You want the cell position ? X and Y coordinates ?
If it is that what u mean, u need to calculate the position using the DGV
left position + width of each cell

Ex:

If u need the position of cell nr 3... u need something like this:

position = dgv.left + dgv.rows(0).wid th + dgv.rows(1).wid th +
dgv.rows(2).wid th

If u don't want this, try explain better your problem.

--

Tiago Salgado

http://weblogs.pontonetpt.com/tiagosalgado
http://www.foruns.org
http://www.portugal-a-programar.org
http://www.revista-programar.info

"Lennart Nielsen" <LN******@uni-systems.comwrot e in message
news:uX******** ******@TK2MSFTN GP06.phx.gbl...
>I can find the X and Y (column/row) coordinates, but not the actual
location (Left,Top) positions.

Any ideas?

Lennart

Feb 8 '07 #2
You might be able to use the dataGridView1.G etCellDisplayRe ctangle
method to get the information you want.

===============
Clay Burch
Syncfusion, Inc.

Feb 8 '07 #3
Clay,

No, that just gives me the column and row index.

lennart

"ClayB" <cl***@syncfusi on.comwrote in message
news:11******** **************@ l53g2000cwa.goo glegroups.com.. .
You might be able to use the dataGridView1.G etCellDisplayRe ctangle
method to get the information you want.

===============
Clay Burch
Syncfusion, Inc.

Feb 8 '07 #4
Lennart Nielsen wrote:
Clay,

No, that just gives me the column and row index.

lennart

I have a DataGridView control called "Grd" and I need to know the bottom
left-hand pixel of the Selected Cell during Cell Editing, I use the
following in the "Grd.CellBeginE dit" and it works perfectly -

Dim X As Integer = Grd.GetCellDisp layRectangle(e. ColumnIndex,
e.RowIndex, False).Left + Grd.Left
Dim Y As Integer = Grd.GetCellDisp layRectangle(e. ColumnIndex,
e.RowIndex, False).Bottom + Grd.Top

You can play with different Properties such as Right, Top etc. Remember
that your DataGridView control is sitting inside a container (either a
Form or maybe a Layout control, or maybe both!) so you must allow for
the position of the DataGridView control in your calculations, which is
why I use "Grd.Top" and "Grd.Left".

Hope this helps.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
Feb 8 '07 #5
Indeed, Clay and ShaneO, you are both correct. I had a brain melt and did
not look for the properties of GetCellDisplayR ectangle. Sorry for doubting
you!

Thanks!

Lennart

"ShaneO" <sp****@optusne t.com.auwrote in message
news:45******** **************@ news.optusnet.c om.au...
Lennart Nielsen wrote:
>Clay,

No, that just gives me the column and row index.

lennart

I have a DataGridView control called "Grd" and I need to know the bottom
left-hand pixel of the Selected Cell during Cell Editing, I use the
following in the "Grd.CellBeginE dit" and it works perfectly -

Dim X As Integer = Grd.GetCellDisp layRectangle(e. ColumnIndex, e.RowIndex,
False).Left + Grd.Left
Dim Y As Integer = Grd.GetCellDisp layRectangle(e. ColumnIndex, e.RowIndex,
False).Bottom + Grd.Top

You can play with different Properties such as Right, Top etc. Remember
that your DataGridView control is sitting inside a container (either a
Form or maybe a Layout control, or maybe both!) so you must allow for the
position of the DataGridView control in your calculations, which is why I
use "Grd.Top" and "Grd.Left".

Hope this helps.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.

Feb 8 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2909
by: Strahimir Antoljak | last post by:
Is it possible (and how?) to get the data grid column name based on the DataGrid.CurrentCell? The DataGrid has assigned a TableStyle comprising selected columns (DataGridTextBoxColumn) from the source DataTable (DataGrid.DataSource=DataTable). I would like to be able to get the column name of the datagrid based on the DataGrid current cell...
1
1603
by: melanieab | last post by:
Hi, I have a datagrid & a datatable, and when I use the mousemove event, I run into trouble. private void dgMouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { System.Windows.Forms.DataGrid.HitTestInfo hitInfo = dg.HitTest(new Point(e.X, e.Y)); .... // find out which cell is entered dg.CurrentCell = new...
7
12574
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's the background for my question... Before I switched my application over to the Fx 2.0, I used a DataGrid to display my data. I would store...
2
4568
by: sklett | last post by:
I have a 2 column DGV. When a user enters a value in cell 0,0 I want to set cell 0,1 as current, when they enter a value in cell 0,1 I want to set cell 1,0 current, etc, etc basically zig-zagging down the rows from left to right. I'm calling this method below in my CellEndEdit event: private void AdvanceCellFocus(DataGridViewCellEventArgs...
0
2492
by: jeastman - Hotmail | last post by:
Hello world Excuse, not to be written English and it helps me with a translator. I am new programming in C#. I made a control inheriting the DataGridView to be able to add controls done by my.
4
20136
by: Michel Walsh | last post by:
Someone has an example, C#, about how to set the cell(int row, int col) as the current cell for a DataGridView. The example, in the help file, about DataGrid.CurrentCell Property (Set) myGrid.CurrentCell = new DataGridCell(1,1); does not work, fro a DataGridView, since we cannot create a DataGridView Cell while specifying only its row...
1
2883
by: =?Utf-8?B?UmljaA==?= | last post by:
I placed a button on a form menustrip for the purpose of causing the horizontal scrollbar of my form to appear so that I can access controls outside of the form's current view (the controls are further to the right of the form than the form's default width - which may take up the entire screen for some users). The form contains panels which...
3
5718
by: Andrus | last post by:
I have DataGridView in virtual mode containing 3500 rows. In code below, assigning to RowCount value to 3500 takes 8 seconds. CPU usage goes high at this time. Stepping by F11 into user code shows few celltemplate property getters and combobox/datecombo constructor calls without database access which does not take a lot of time. Debug...
4
3371
Luckie
by: Luckie | last post by:
Hi All experts there, I am developing a software using datagridview (vb6 feels better) and i am using virtualMode. it shows the focus blue box but it is not possible to fill data to the first cell programatically. what is wrong here. also i have used from within a button_click event as follows 1- MyGrid.CurrentCell.Value = 22 2-...
0
7583
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7885
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7638
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...
1
5484
isladogs
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...
0
5213
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...
0
3642
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...
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.