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

Datagrid MouseDown event

Hello all,
I'm trying to capture the column and row of the datagrid cell clicked. I'm
have problems figuring this out. I think it is simple but eludes me.
I have a datagrid and a MouseDown event...

private void dataGrid1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
DataGrid dg = (DataGrid)sender;
ycolumn = dg.CurrentCell.ColumnNumber;
xrow = dg.CurrentCell.RowNumber;
label4.Text = ycolumn.ToString();
}

In label4 I'm just putting the column on the form so I can see what I
clicked. The problem is, that what ever column I click, label4 (and
therefore ycolumn) shows the very last column I clicked. For example, when
it first runs label4 has 0. If I click click column 3, label4 shows 0. Then
I click column 5, label4 then shows 3. I then click column 1, label4 now
shows 5. It's like it shows the last column. Does anyone know what I'm doing
wrong?
Thanks
Nov 15 '05 #1
2 7566
Your current cell isn't current yet on Mouse Down. I think .HitTest will
work for you or you could change the event to CellChanged...

HTH

Bill
"Randy" <rf*****@bellsouth.net> wrote in message
news:%2*****************@tk2msftngp13.phx.gbl...
Hello all,
I'm trying to capture the column and row of the datagrid cell clicked. I'm
have problems figuring this out. I think it is simple but eludes me.
I have a datagrid and a MouseDown event...

private void dataGrid1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
DataGrid dg = (DataGrid)sender;
ycolumn = dg.CurrentCell.ColumnNumber;
xrow = dg.CurrentCell.RowNumber;
label4.Text = ycolumn.ToString();
}

In label4 I'm just putting the column on the form so I can see what I
clicked. The problem is, that what ever column I click, label4 (and
therefore ycolumn) shows the very last column I clicked. For example, when
it first runs label4 has 0. If I click click column 3, label4 shows 0. Then I click column 5, label4 then shows 3. I then click column 1, label4 now
shows 5. It's like it shows the last column. Does anyone know what I'm doing wrong?
Thanks

Nov 15 '05 #2
That worked!
Thanks for you help...
Have a good day!
"William Ryan" <do********@comcast.nospam.net> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl...
Your current cell isn't current yet on Mouse Down. I think .HitTest will
work for you or you could change the event to CellChanged...

HTH

Bill
"Randy" <rf*****@bellsouth.net> wrote in message
news:%2*****************@tk2msftngp13.phx.gbl...
Hello all,
I'm trying to capture the column and row of the datagrid cell clicked. I'm have problems figuring this out. I think it is simple but eludes me.
I have a datagrid and a MouseDown event...

private void dataGrid1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
DataGrid dg = (DataGrid)sender;
ycolumn = dg.CurrentCell.ColumnNumber;
xrow = dg.CurrentCell.RowNumber;
label4.Text = ycolumn.ToString();
}

In label4 I'm just putting the column on the form so I can see what I
clicked. The problem is, that what ever column I click, label4 (and
therefore ycolumn) shows the very last column I clicked. For example, when it first runs label4 has 0. If I click click column 3, label4 shows 0.

Then
I click column 5, label4 then shows 3. I then click column 1, label4 now
shows 5. It's like it shows the last column. Does anyone know what I'm

doing
wrong?
Thanks


Nov 15 '05 #3

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

Similar topics

0
by: dominic | last post by:
Hi, I was wondering if it was possible to know if the ALT key is down in a MouseDown event. I checked the MouseEventArgs class but it dosen't seem to hold this information. Maybee there is...
2
by: JJ | last post by:
Hi All, I need to create a MouseDown event for a picture box . Am I doing the following right? pictureBox.MouseDown += new System.WinForms.MouseEventHandler(pictureBox_MouseDown) Then
2
by: Boaz Ben-Porat | last post by:
Is there any way to determine if the CTRL key is pressed from a MouseDown event on a DataGrid ? TIA Boaz ben-Porat DataPharm a/s Denmark
1
by: GregM | last post by:
I have a read only datagrid that is designed to coordinate itself with textboxes. When the user clicks on a row in the datagrid, detailed data for that row is displayed for editing in the...
1
by: Jensen Hoh | last post by:
In VB6 DataGrid, there have a event call HeadClick which will fire when user click on the Grid Header Is there any similiar event for DataGrid in C#? Thank you *** Sent via Developersdex...
4
by: rsmith | last post by:
How can I capture the MouseDown event on a Label ? I entered thr following code and got a " cannot handle Event 'MouseDown' because they do not have the same signature." Private Sub...
0
by: LCH | last post by:
hi i would like to know how to capture a datagrid keypress event. I have form contains of a datagrid with 5 rows and 5 colums and a button. When i press on the enter button at the last row n...
1
by: phcmi | last post by:
Within a mousedown event, can you please show a code sample of how to ascertain whether the CTRL and/or ALT and/or SHIFT keyboard key is pressed? Thank you
2
by: Peter | last post by:
Hi I've discovered a bizarre Windows Forms (VB.NET) behavior that is resulting in a Form not being able to be moved. To reproduce this: 1) Create yourself a new Windows Application in Visual...
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
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...
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...
0
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
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
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...

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.