473,322 Members | 1,620 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,322 software developers and data experts.

How to find the row clicked in a datagrid

Hi

How do I find the row I clicked on the datagird

Thanks in advance.
Jul 21 '05 #1
3 1706
In the MouseUp event for the Datagrid place the following code

miHitRow = dg.CurrentCell.RowNumber
or Call one of the following methods in the Datagrid MouseUp event.
Public Function GetClickedRow(ByVal e As _
System.Windows.Forms.MouseEventArgs, _
ByRef dbg As DataGrid) As Integer
' this method is called from the mouseup event of a datagrid
' returns the clicked row number (zero based)
Try
Dim pt As Point = New Point(e.X, e.Y)
Dim hti As DataGrid.HitTestInfo = dbg.HitTest(pt)
Return hti.Row
Catch ex As System.Exception
' ignore the error if the user clicked outside the grid rows,
' e.g., in the header...
End Try
End Function

Public Sub GetClickedCell(ByRef iRow As Integer, _
ByRef iCol As Integer, _
ByRef dbg As DataGrid, _
ByVal e As System.Windows.Forms.MouseEventArgs)
Try
Dim pt As Point = New Point(e.X, e.Y)
Dim hti As DataGrid.HitTestInfo = dbg.HitTest(pt)

Catch ex As System.Exception
MsgBox(ex.ToString)
End Try

End Sub
HTH
Les Smith
http://www.knowdotnet.com

"Kshitij" <an*******@discussions.microsoft.com> wrote in message
news:B0**********************************@microsof t.com...
Hi,

How do I find the row I clicked on the datagird?

Thanks in advance.

Jul 21 '05 #2
Dim pt As Point = New Point(e.X, e.Y)

Dim hti As DataGrid.HitTestInfo = dbg.HitTest(pt)

If hti.Type = DataGrid.HitTestType.Cell Then

dbg.CurrentCell = New DataGridCell(hti.Row, hti.Column)

HTH

Les Smith

http://www.KnowDotNet.com

"Kshitij" <an*******@discussions.microsoft.com> wrote in message
news:B0**********************************@microsof t.com...
Hi,

How do I find the row I clicked on the datagird?

Thanks in advance.

Jul 21 '05 #3
Dim pt As Point = New Point(e.X, e.Y)

Dim hti As DataGrid.HitTestInfo = dbg.HitTest(pt)

If hti.Type = DataGrid.HitTestType.Cell Then

dbg.CurrentCell = New DataGridCell(hti.Row, hti.Column)

HTH

Les Smith

http://www.KnowDotNet.com

"Kshitij" <an*******@discussions.microsoft.com> wrote in message
news:B0**********************************@microsof t.com...
Hi,

How do I find the row I clicked on the datagird?

Thanks in advance.

Jul 21 '05 #4

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

Similar topics

1
by: Kshitij | last post by:
Hi How do I find the row I clicked on the datagird Thanks in advance.
12
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option...
1
by: Stanley J Mroczek | last post by:
I am trying to load a dropdownlist in VB when the edit is clicked in a datagrid. How do i call Sub loaddd to load the dropdownlist <asp:TemplateColumn runat="server" HeaderText="Id Type Option"...
12
by: Jim H | last post by:
We ahve a .NET web page that we dynamically create a bunch of DataGrids and add them to a place holder. When the user hits submit we need to go through all of the DataGrids to get some data. We...
2
by: Daniel Walzenbach | last post by:
Hi, I created an ASP.NET Datagrid where a single row can be selected by clicking anywhere on the row (according to...
3
by: Terry Olsen | last post by:
I have a DataGrid with a Template Column. In the ItemTemplate I have an ImageButton. I want to have the user select a row by clicking on the ImageButton. When the user clicks an ImageButton,...
1
by: Tor Inge Rislaa | last post by:
Find what cell is clicked in a datagrid When clicking a cell in the datagrid I can't see that the click event is raised. As I can understand the click event is raised when the column or row...
1
by: DotNetDev | last post by:
Hi, I have a datagrid. <asp:DataGrid id="DataGrid1" runat="server" Height="237px" Width="280px" AutoGenerateColumns="False" AlternatingItemStyle-BackColor="#e9e9e9" ShowHeader="false" ...
2
by: benfly08 | last post by:
Hi, everyone. I got a weird problem for my C# program. In my program, I use a DataGrid to display data. I bind the DataGrid to a DataTable. I made all the cells in DataGrid ReadOnly as True. So...
1
nateraaaa
by: nateraaaa | last post by:
While working on a recent project I discovered how useful the CommandArgument property can be. I needed to determine the record_id of a row displayed in my datagrid. When the user clicked the Edit...
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...
1
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.