473,395 Members | 1,456 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,395 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 1710
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.