473,781 Members | 2,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

finding clicked row in datagrid?

VMI
Hi,
I have a Windows datagrid that's attached to a filled datatable. The grid
also has a tablestyle. Since the data from the grid comes from a
datatatable, how can I retrieve the data from a specific table row once a
user clicks on a grid row? I already have the code that lets me know what
grid row the user clicked on, but, for example, if I want to retrieve the
value of the 5th column in the grid, I'm currently using myGrid[rowNum,
4].ToString(). But If I decide to change the position of "Name" to column 8,
I'll have to change this code (eg. myGrid[rowNum, 7].ToString() ). Is there
any other alternative?

Thanks.
Nov 16 '05 #1
2 1723
Hi VMI,

Your question as I understood is this:
you have a datagrid, bound to a datatable. The columns, or the sorting etc.
might change in the datagrid.
Regardless of the column position, or the current sort, you want to obtain
the datarow which the user has currently selected in the datagrid. Is this
right?

If yes, then you could use the Binding Manager to find out the current
object/row that the bound datagrid is now referring to. For example, to get
the current row, use:
((CurrencyManag er)BindingConte xt[datatablename]).Current.
Cast this into a datarow (or your typed one), and then use it.

This is a good article which explains the data binding procedure in windows
forms:
http://msdn.microsoft.com/library/en...dingadonet.asp

HTH,
Rakesh Rajan

"VMI" <vo******@yahoo .com> wrote in message
news:OL******** ******@TK2MSFTN GP09.phx.gbl...
Hi,
I have a Windows datagrid that's attached to a filled datatable. The grid
also has a tablestyle. Since the data from the grid comes from a
datatatable, how can I retrieve the data from a specific table row once a
user clicks on a grid row? I already have the code that lets me know what
grid row the user clicked on, but, for example, if I want to retrieve the
value of the 5th column in the grid, I'm currently using myGrid[rowNum,
4].ToString(). But If I decide to change the position of "Name" to column 8, I'll have to change this code (eg. myGrid[rowNum, 7].ToString() ). Is there any other alternative?

Thanks.

Nov 16 '05 #2
VMI
Thanks. It worked.
Can I use the Binding Manager to retrieve all the rows that are highlighted
(instead of just one)?
In my code, this is how I use it when the row is already highlighted:

DataRowView rowViewAudit = (DataRowView)
((CurrencyManag er)BindingConte xt[_table_auditAdd ress]).Current;

But this only works when there's only one line chosen. I tried declaring
rowViewAudit as DataRowView[] and use foreach, but it doesn't work.

Thanks.
"Rakesh Rajan" <ra************ **********@hotm ail.com> wrote in message
news:O9******** ******@tk2msftn gp13.phx.gbl...
Hi VMI,

Your question as I understood is this:
you have a datagrid, bound to a datatable. The columns, or the sorting etc. might change in the datagrid.
Regardless of the column position, or the current sort, you want to obtain
the datarow which the user has currently selected in the datagrid. Is this
right?

If yes, then you could use the Binding Manager to find out the current
object/row that the bound datagrid is now referring to. For example, to get the current row, use:
((CurrencyManag er)BindingConte xt[datatablename]).Current.
Cast this into a datarow (or your typed one), and then use it.

This is a good article which explains the data binding procedure in windows forms:
http://msdn.microsoft.com/library/en...dingadonet.asp
HTH,
Rakesh Rajan

"VMI" <vo******@yahoo .com> wrote in message
news:OL******** ******@TK2MSFTN GP09.phx.gbl...
Hi,
I have a Windows datagrid that's attached to a filled datatable. The grid also has a tablestyle. Since the data from the grid comes from a
datatatable, how can I retrieve the data from a specific table row once a user clicks on a grid row? I already have the code that lets me know what grid row the user clicked on, but, for example, if I want to retrieve the value of the 5th column in the grid, I'm currently using myGrid[rowNum,
4].ToString(). But If I decide to change the position of "Name" to
column 8,
I'll have to change this code (eg. myGrid[rowNum, 7].ToString() ). Is

there
any other alternative?

Thanks.


Nov 16 '05 #3

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
2807
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,...
2
7076
by: Charlie | last post by:
Hi: Using the WinForms DataGrid, I would like to have the entire row highlight rather than just the cell that was last clicked. How do you do this? Thanks, Charlie
3
4496
by: Rob | last post by:
You can find datagrid in page by refering the form. Gatagrid is a child control of Form. Here is the code ----------------- Dim ctl As New Control For Each ctl In Page.FindControl("form1").Controls If TypeOf ctl Is DataGrid Then Response.Write(ctl.ID)
2
3182
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
1494
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?
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...
0
9474
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,...
0
10308
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
10143
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...
0
9939
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...
0
8964
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
7486
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
5375
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...
1
4040
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
2870
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.