PC Review


Reply
Thread Tools Rate Thread

datagrid how to iterate through rows in a column and the set that found row as the first row?

 
 
Wiredless
Guest
Posts: n/a
 
      5th Jun 2005
Hi

I need to loop through the datagrid rows for a column to search for specific
text then make that row visible and or selected. I can do this in a listview
fairly easy but i dont see how i can do it with a datagrid

Any pointers?

Thanks


 
Reply With Quote
 
 
 
 
Tim Wilson
Guest
Posts: n/a
 
      5th Jun 2005
You could do something similar to the following.

DataTable dt = new DataTable("MyTable");
dt.Columns.Add("MyColumn", typeof(string));
for (int x = 0; x < 25; x++)
{
dt.Rows.Add(new object[] {x.ToString()});
}
this.dataGrid1.DataSource = dt.DefaultView;

....

DataView dv = this.dataGrid1.DataSource as DataView;
if (dv != null)
{
for (int x = 0; x < dv.Count; x++)
{
if ((string)dv[x].Row["MyColumn"] == "SomeText")
{
this.dataGrid1.CurrentRowIndex = x;
this.dataGrid1.Select(x);
break;
}
}
}

--
Tim Wilson
..Net Compact Framework MVP

"Wiredless" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi
>
> I need to loop through the datagrid rows for a column to search for

specific
> text then make that row visible and or selected. I can do this in a

listview
> fairly easy but i dont see how i can do it with a datagrid
>
> Any pointers?
>
> Thanks
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid Column/Rows Expansion or Defaults schaapiee Microsoft Dot NET 0 15th Mar 2007 08:34 PM
To Delete the specific rows when blank is found on column A =?Utf-8?B?ZGRpaWNj?= Microsoft Excel Programming 3 5th Aug 2005 05:32 AM
Re: Delete Rows when Blanks are found in Column A:A Norman Jones Microsoft Excel Programming 0 4th Aug 2005 10:46 AM
DataGrid column with numbers of rows Przemo Microsoft ASP .NET 2 20th Jul 2004 01:27 PM
searching a datagrid's rows and displaying rows where item was found Angel Microsoft C# .NET 0 26th Apr 2004 05:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:03 AM.