473,791 Members | 2,949 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 1754
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
2808
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
2190
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
3183
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
1958
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
1497
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
1348
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
13309
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
9669
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10155
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
9995
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7537
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
5431
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
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
3
2916
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.