Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 6th, 2004, 11:37 AM
Authorized User
 
Join Date: Jun 2003
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to cover only the selected lines in a DataGrid

Hi again...

There is a DataGrid method or any way (like Foreach) to cover only the 10 or 20 selected lines in a DataGrid with 3000 lines???

Thanks....
 
Old December 8th, 2004, 12:23 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello,
get the selected rows by below code(they are copied in an arraylist),
Code:
public ArrayList GetSelectedRows(DataGrid dg)  
{ 
     ArrayList al = new ArrayList(); 
     CurrencyManager cm = (CurrencyManager)this.BindingContext[dg.DataSource, dg.DataMember]; 
     DataView dv = (DataView)cm.List; 
     for(int i = 0; i < dv.Count; ++i) 
     { 
          if(dg.IsSelected(i)) 
               al.Add(i); 
     } 
     return al; 
}
then set RowFilter property of your DataView with the ID's in your arraylist,
Code:
    string s=""; 
    foreach(object o in GetSelectedRows(dataGrid1)) 
     { 
          s+= "ID ="+o.ToString()+"OR"; 
     }
     //eliminate last "OR" from your string
     dv.RowFilter=s;
     //set the datasource of your grid with dv and bind ur grid
(this method just works in Windows Applications),
HtH.

_____________________________
Mehdi.
software engineering student.
Looking for a good job for summer 2005.
 
Old December 9th, 2004, 02:27 PM
Authorized User
 
Join Date: Jun 2003
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks MEHDI62B,

your answer solve all of my problems...

Thanks a lot...
 
Old January 19th, 2005, 10:44 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

(ur welcome)another point,
instead of string variables,usually it's better to use StringBuilder because using strings
causes the creation of temporary strings,
Code:
//instead of 
s+=<yourVariable>
//use a StringBuilder
StringBuilder s = new StringBuilder();
s.Append(<yourVariable>);
(another theoretical calculation from a college student :D)!

_____________________________
Mehdi.
software engineering student.
Looking for a good job for summer 2005.





Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i cover all datagrid rows ??? thomaz C# 1 November 30th, 2006 10:19 PM
Datagrid scroll count (Lines) VB.NET 2003 peterasimpson VB.NET 4 November 24th, 2005 05:34 PM
Datagrid scroll count (Lines) VB.NET 2003 peterasimpson VB How-To 1 November 24th, 2005 12:33 AM
datagrid dorpdownlist selected san_only ASP.NET 1.x and 2.0 Application Design 1 June 5th, 2003 09:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.