473,396 Members | 2,009 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,396 software developers and data experts.

Grab data from Data Grid

This is in a WinForm.
How do I grab all the data in all the cells of the row the user selected OR
all the data in all the cells if the user selects one of the cells in the
row? What event should I put the code in?

Nov 17 '05 #1
3 1281
Hi,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to get all the items in the
row that is selected in a WinForm DataGrid. If there is any
misunderstanding, please feel free to let me know.

We can use the CurrencyManager.Current to get the row selected. The return
value is a DataRowView object. We can enumerate the Item property of it to
get all the values. You can check the following links for more information.

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwindowsformscurrencymanagerclasstopic.a sp

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemdatadatarowviewclassitemtopic.asp

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 17 '05 #2
Your response is to complex. I just want basic code to retrieve data from
the row the user has selected, and in which event the code should be.

"Kevin Yu [MSFT]" wrote:
Hi,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to get all the items in the
row that is selected in a WinForm DataGrid. If there is any
misunderstanding, please feel free to let me know.

We can use the CurrencyManager.Current to get the row selected. The return
value is a DataRowView object. We can enumerate the Item property of it to
get all the values. You can check the following links for more information.

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwindowsformscurrencymanagerclasstopic.a sp

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemdatadatarowviewclassitemtopic.asp

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 17 '05 #3
Hi,

Here I wrote a code snippet. Make sure that when getting the
CurrencyManager, we have to use the same data source object and data
memeber as we set to the DataGrid.

private CurrencyManager cm;

private void Form1_Load(object sender, System.EventArgs e)
{
DataSet ds = new DataSet();
this.sqlDataAdapter1.Fill(ds);
this.dataGrid1.DataSource = ds.Tables[0];
this.cm = (CurrencyManager)this.BindingContext[ds.Tables[0]];
this.cm.PositionChanged +=new EventHandler(cm_PositionChanged);
}

private void cm_PositionChanged(object sender, EventArgs e)
{
DataRowView dr = (DataRowView)this.cm.Current;
//Do whatever with the DataRowView object here.
}

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jordan O'Hare | last post by:
Hello Everyone, I am after some help with the following: I have a windows application that contains a list box and two data grids. All three controls are binded to a dataset that contains...
2
by: kk | last post by:
Have 2 problems, any help is appreciated. Tab with Grids -------------- BL - fetching data from DB ( 5 secs - 10 rows) Grid Laod - 20 secs Grid Paint on tab change - 20 secs Problem: The...
5
by: pmud | last post by:
Hi, I need to display columns in a data grid based on 7 different queries. Now I have 32 questions: 1. Is it possble to have 1 single data adapter with 7 queries & 1 data set or do I need to...
2
by: Josef Meile | last post by:
Hi, I'm using a ComboBox, some Textboxes, and a DataGrid to represent a many-to-many relationship between Person and Course. Each time that I change the value in the ComboBox (which for now is...
3
by: pmud | last post by:
Hi, I have a web page (asp.net, code:c#). I havean html table with text boxes. Based on the user input , records are displayed in the data grid below it. Now the datagrid has a large no. of...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
0
by: Charles Law | last post by:
The ControlPaint class looks like the ideal way to draw grab handles, a grid, and other designer-like stuff in a windows form, but I can't make it work. I realise I need to use SetStyle to set...
9
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New...
6
by: insirawali | last post by:
Hi all, I have this problem, i need to know is there a way i cn use the data adapter's update method in this scenario. i have 3 tables as below create table table1{ id1 int identity(1,1)...
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
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
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...
0
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...
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...
0
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,...

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.