473,804 Members | 3,559 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1756
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(B yVal e As _
System.Windows. Forms.MouseEven tArgs, _
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.HitTes tInfo = dbg.HitTest(pt)
Return hti.Row
Catch ex As System.Exceptio n
' 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.MouseEven tArgs)
Try
Dim pt As Point = New Point(e.X, e.Y)
Dim hti As DataGrid.HitTes tInfo = dbg.HitTest(pt)

Catch ex As System.Exceptio n
MsgBox(ex.ToStr ing)
End Try

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

"Kshitij" <an*******@disc ussions.microso ft.com> wrote in message
news:B0******** *************** ***********@mic rosoft.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.HitTes tInfo = dbg.HitTest(pt)

If hti.Type = DataGrid.HitTes tType.Cell Then

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

HTH

Les Smith

http://www.KnowDotNet.com

"Kshitij" <an*******@disc ussions.microso ft.com> wrote in message
news:B0******** *************** ***********@mic rosoft.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.HitTes tInfo = dbg.HitTest(pt)

If hti.Type = DataGrid.HitTes tType.Cell Then

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

HTH

Les Smith

http://www.KnowDotNet.com

"Kshitij" <an*******@disc ussions.microso ft.com> wrote in message
news:B0******** *************** ***********@mic rosoft.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
285
by: Kshitij | last post by:
Hi How do I find the row I clicked on the datagird Thanks in advance.
12
2809
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 Description"></asp:BoundColumn> <asp:TemplateColumn runat="server" HeaderText="Id Type Option" "> <itemtemplate> <asp:label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "TypeOption") %>' /> <asp:label runat="server" ID="LlbTypeOption" Visible=False...
1
1810
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" SortExpression="IdTypeOption"> <itemtemplate> <asp:label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "TypeOption") %>' /> <asp:label runat="server" ID="LlbTypeOption" Visible=False Text='<%# DataBinder.Eval(Container.DataItem,...
12
2191
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 can't seem to find the grids on the post back, the PlaceHolder.Controls.Count is 0. How do we get that data back. The DataGrids have check boxes that the user may have checked. Those are the rows we want to get so we can't just requery and...
2
3185
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 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchTopQuestionsAboutASPNETDataGridServerControl.asp, Selecting Rows by Clicking Anywhere). Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, _ ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
3
1959
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, how can I tell which row he clicked on, and then change the image for the ImageButton in that row, and make sure all the images in the other rows are default? I have two Images, one of a button in the "Up" position, and another of the same...
1
1498
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 header is clicked. Is there an event that can be used to find the current cell when you click it?
1
1349
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" ShowFooter="false" > <Columns> <asp:TemplateColumn HeaderStyle-Height="0"> <ItemTemplate>
2
2088
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 I can only Click on the cell but not change them. Now, after I display the data, I clicked on one cell, then I clicked a button which will *virtually* go to the other form.(The reason why I said *virtually* is because I only use one form for...
1
13310
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 ImageButton I needed to redirect the user to the Edit page where the data on the page would be prepopulated with data from the database. I tried several things without success then discovered that the CommandArgument property could be used for this...
0
10567
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10310
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9138
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2983
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.