473,883 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Looping through datagrid rows

Dan
I'd like to loop through selected datagrid rows and extract specified
columns from those rows. How would I do that?

Thanks...

Dan
Nov 15 '05 #1
6 35485
L#
On Thu, 5 Feb 2004 17:13:03 -0500, "Dan" <da*@dontspamme .com> wrote:
I'd like to loop through selected datagrid rows and extract specified
columns from those rows. How would I do that?

Thanks...

Dan


Don't try to loop through the datagrid rows, but loop through the
datatable rows instead (so use the datasource of your datagrid instead
of the datagrid itself).
--
Ludwig
mailto:ludwig_( nospamplease)st uyck@pandora(no spamplease).be
Nov 15 '05 #2
Dan
How can I determine whether the row is selected in the datagrid? For
example, I click on rows 3, 7, and 9 of the datagrid. When I loop through
the dataset rows, how do I determine that they are selected?
"L#" <ludwig_(nospam please)stuyck@p andora(nospampl ease).be> wrote in message
news:vm******** *************** *********@4ax.c om...
On Thu, 5 Feb 2004 17:13:03 -0500, "Dan" <da*@dontspamme .com> wrote:
I'd like to loop through selected datagrid rows and extract specified
columns from those rows. How would I do that?

Thanks...

Dan


Don't try to loop through the datagrid rows, but loop through the
datatable rows instead (so use the datasource of your datagrid instead
of the datagrid itself).
--
Ludwig
mailto:ludwig_( nospamplease)st uyck@pandora(no spamplease).be

Nov 15 '05 #3
L#
On Thu, 5 Feb 2004 17:40:55 -0500, "Dan" <da*@dontspamme .com> wrote:
How can I determine whether the row is selected in the datagrid? For
example, I click on rows 3, 7, and 9 of the datagrid. When I loop through
the dataset rows, how do I determine that they are selected?


Here's a little method that does the trick:

/// <summary>
/// Returns an arraylist with datarows that are selected in the
/// datagrid.
/// </summary>
/// <param name="datagrid" >Datagrid.</param>
/// <returns>Arrayl ist with datarows that are selected in the
/// datagrid</returns>

public ArrayList GetSelectedRows (DataGrid datagrid)
{
ArrayList arrSelectedRows = new ArrayList();
DataSet dset = (DataSet)datagr id.DataSource;
for (int i=0; i<dset.Tables[0].Rows.Count; i++)
{
if (datagrid.IsSel ected(i))
{
DataRow drow = dset.Tables[0].Rows[i];
arrSelectedRows .Add(drow);
}
}
return arrSelectedRows ;
}
--
Ludwig
mailto:ludwig_( nospamplease)st uyck@pandora(no spamplease).be
Nov 15 '05 #4
Dan
Thanks!

"L#" <ludwig_(nospam please)stuyck@p andora(nospampl ease).be> wrote in message
news:is******** *************** *********@4ax.c om...
On Thu, 5 Feb 2004 17:40:55 -0500, "Dan" <da*@dontspamme .com> wrote:
How can I determine whether the row is selected in the datagrid? For
example, I click on rows 3, 7, and 9 of the datagrid. When I loop throughthe dataset rows, how do I determine that they are selected?


Here's a little method that does the trick:

/// <summary>
/// Returns an arraylist with datarows that are selected in the
/// datagrid.
/// </summary>
/// <param name="datagrid" >Datagrid.</param>
/// <returns>Arrayl ist with datarows that are selected in the
/// datagrid</returns>

public ArrayList GetSelectedRows (DataGrid datagrid)
{
ArrayList arrSelectedRows = new ArrayList();
DataSet dset = (DataSet)datagr id.DataSource;
for (int i=0; i<dset.Tables[0].Rows.Count; i++)
{
if (datagrid.IsSel ected(i))
{
DataRow drow = dset.Tables[0].Rows[i];
arrSelectedRows .Add(drow);
}
}
return arrSelectedRows ;
}
--
Ludwig
mailto:ludwig_( nospamplease)st uyck@pandora(no spamplease).be

Nov 15 '05 #5
If the grid is sorted then this code won't work. Is there a solution
for this problem with grid sorting enabled?

Thank you.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #6
L#
On Thu, 05 Feb 2004 15:59:34 -0800, Koushik K <ko*******@hotm ail.com>
wrote:
If the grid is sorted then this code won't work. Is there a solution
for this problem with grid sorting enabled?

Thank you.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


I made a little modification. The datatable itself is not sorted, but
the default dataview is sorted if the grid is sorted:

public ArrayList GetSelectedRows (DataGrid datagrid)
{
ArrayList arrSelectedRows = new ArrayList();
DataSet dset = (DataSet)datagr id.DataSource;
for (int i=0; i<dset.Tables[0].Rows.Count; i++)
{
if (datagrid.IsSel ected(i))
{
DataRow drow =
dset.Tables[0].DefaultView[i].Row;
arrSelectedRows .Add(drow);
}
}
return arrSelectedRows ;
}
--
Ludwig
mailto:ludwig_( nospamplease)st uyck@pandora(no spamplease).be
Nov 15 '05 #7

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

Similar topics

1
5395
by: Diva | last post by:
Hi, I have a data grid in my application. It has 20 rows and I have set the page size as 5. I have a Submit button on my form and when I click on Submit, I need to loop through the rows in the datagrid. Using the items collection just gives me the 5 rows that are displayed on the screen. Is there any way of looping through all the rows in the grid?
1
5296
by: Craig Banks | last post by:
If a row of data in a dataset has a lot of columns the row displaying the data in a datagrid will run way off the screen. What I'd like to do is display a row of data over several datagrid rows so the user doesn't have to scroll horizontally. Essentially, I want to wrap a datagrid row (not text in individual columns) with as much control as possible. Make sense? While this seems simple enough on the surface, I can't figure out how to do...
1
1148
by: ruca | last post by:
There is anyway to resize dinamically datagrid rows? I have a datagrid with 5 rows for each page. What happens is if in the 3rd page there is only one row to show, that row stays to large in comparation with rows of before pages. How can I set the row space always the same, no matter if there is 5 or 1 row(s) in datagrid pages?? --
0
1752
by: sunilkumar Reddy via DotNetMonster.com | last post by:
hai all first we have taken binded grid Export to excel data from ultrawebgrid (or) datagrid rows, Each row data Expoting to one worksheet in excel workbook, like as grid row1 data contain sheet1 grid row2 data contain sheet2 grid row3 data contain sheet3 we have pressing one button ultrawebgrid (or) datagrid rows data to export
6
1998
by: Roy | last post by:
Since a datagrid is just an html table anyways, this seems like it should be easy but it's giving me a hard time. In ItemDataBound sub I'm trying to kick off javascript code using response.write(). The javascript code is contained within an IF block and if e.Item.Cells(0).Text = myVariable then the row gets hidden. A user can still view those rows later with a buttonclick. Only problem is, I aside from what I've described above, I...
0
1095
by: Trint Smith | last post by:
the less the data going to my datagrid, the wider the lines and columns...how can i keep the datagrid rows and columns the same size no matter how much data is being displayed? thanks, Trint ..Net programmer trintsmith@hotmail.com *** Sent via Developersdex http://www.developersdex.com ***
2
2607
by: | last post by:
Hi all. I need to change datagrid rows height dinamically, so each row shows all the text contained in the cell. There is a "PreferredRowHeight" property in the TableStyle of a datagrid, but it change all rows height to the same value. I need to have different row heights. Can you help me?? Bye Francesco
1
6584
by: Fred Morrison | last post by:
Is it just me or is there something grossly wrong with the Windows Forms DataGrid control that won't tell me the row count inside it? I'm not talking about just visible rows (what the heck good is that, pray tell?). I want the TOTAL rows count in the DataGrid control. Oh sure, there could be a bound DataTable, DataView, or whatever that can be rextracted; but, that means my User Interface has to know something about how the data was...
5
1433
by: magmo | last post by:
Hi I have a datagrid that have checkboxes added to it and there is also a button that I want to use as a check what rows has been selected in the datagrid. But when I use this piece if code the program just close when I press the button that is supposed to show the selected rows in the datagrid <code>
0
9944
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
9796
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
11153
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
10757
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
10860
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
10420
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
7975
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
6002
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4225
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.