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

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 1706
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:
((CurrencyManager)BindingContext[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**************@TK2MSFTNGP09.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)
((CurrencyManager)BindingContext[_table_auditAddress]).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**********************@hotmail.com> wrote in message
news:O9**************@tk2msftngp13.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:
((CurrencyManager)BindingContext[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**************@TK2MSFTNGP09.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
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"...
2
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
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...
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...
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...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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...
0
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,...
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...

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.