Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


C# DataGrid Filtering and Sorting


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Strayfire   Members   -  Reputation: 162

Like
0Likes
Like

Posted 28 July 2005 - 10:33 AM

I'm trying to find the first occurance of a certain value in one column of information in my DataGrid and then set the scroll to that row. The grid can be both sorted and filtered by the user, which is causing a problem. The data table that I am retrieving from the data grid is the original unsorted and unfiltered table. How do I get a copy of what is actually visible in the DataGrid, not the original unmodifed DataTable?

Sponsor:

#2 intrest86   Members   -  Reputation: 742

Like
0Likes
Like

Posted 28 July 2005 - 10:39 AM

Try using a DataView. It encapsulates your DataSet and then lets you play with the data as far as sorting and filtering goes, while the actual DataSet isn't touched. You can then bind to the DataView to get the post-processed data.

As far as getting a copy, just keep the DataView around. Whenever you enumerate through it you will see exactly what the DataGrid sees.

#3 Strayfire   Members   -  Reputation: 162

Like
0Likes
Like

Posted 28 July 2005 - 10:53 AM

Sorry, I haven't really had much experience with any of these classes up until now. Could you please provide an example?

#4 intrest86   Members   -  Reputation: 742

Like
0Likes
Like

Posted 28 July 2005 - 11:09 AM

Quote:
Original post by Strayfire
Sorry, I haven't really had much experience with any of these classes up until now. Could you please provide an example?

I'm assuming you have already used the DataSets from your post. In that case, you really do almost nothing different. A very simply example would be if we got a list of first and last names from a database. We decide we want to sort the first names of everyone who's last name is Smith.

DataSet ds = GetMyData(); //Get the DataSet you want to work with (usually from a database)
DataView dv = new DataView(ds.Tables(0)); //Create a DataView that is a 'view' of one of the tables in our DataSet. We will use this to sort and filter.

//Sort and Filter Here
dv.Sort = "FirstName";
dv.RowFilter = "LastName='Smith'";

//Set the DataView to be the DataGrid's source for info, and then call DataBind()
myDataGrid.DataSource = dv;
myDataGrid.DataBind();


#5 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

0Likes

Posted 29 July 2005 - 12:40 AM

There doesn't seem to be a DataBind() method. Is that just for web forms?

#6 intrest86   Members   -  Reputation: 742

Like
0Likes
Like

Posted 29 July 2005 - 03:59 AM

Quote:
Original post by Anonymous Poster
There doesn't seem to be a DataBind() method. Is that just for web forms?

Ah, yes. DataBind is just for web forms. Sorry, I don't do nomral applications that often. In a standard form App you just have to set the datasource and it should handle it from there.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS