[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1522
  • Last Modified:

Sort or filter unbound column of a bound datagridview

I have a bound datagridview. I have added two unbound columns. After i verify the data of the  grid, set forcolor of the cell that has invalid value and i set this unbound column's checkbox to be true. In order for me to be able to check, i had to set the grid's virtualmode = false . So far everything is working well.
Now, I want to sort my grid based on this new unbound column i call "FailedData" so that all the rows with checked "FailedData" will be together so that user knows which rows should be edited. i can either filter and show only the rows with checkbox checked or sort. But according to msdn, you can not sort  unbound column of a bound datagriedview.
Any suggestion?
0
RekhaShah
Asked:
RekhaShah
  • 5
  • 5
1 Solution
 
UnifiedISCommented:
Can you include the 2 new columns with your bound data source?  They don't need a value until your validation and you could hide them (visible = false) until you need to show them if you want.

0
 
RekhaShahAuthor Commented:
i guess, I can try it.  But ideally, i would like to sort of filter. Can you filter rows based on formatting? e.g.display only the rows with any of the cell with red fore color?
0
 
UnifiedISCommented:
If your 2 new columns are part of your data source then you will be able to sort by those columns.  

yes, could filter based on formatting but I don't think you could sort based on formatting.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
RekhaShahAuthor Commented:
How would you filter based on formatting?
 also, even for filtering based on formatting, I do need to make these columns part of my database. right?
0
 
UnifiedISCommented:
Filtering based on formatting is possible but logically, it's backwards.

As for part of the database, you don't need to add columns to tables but you do need to add columns to your query.

A SQL query with a "fake" column to be populated later in code:
SELECT *, '' AS FailedData FROM Table

0
 
RekhaShahAuthor Commented:
So,  i think, i should populate  my FailedData column in the stored procedure and then get the recordset, and now business as usual? Let me try it this evening and post back again.  i was  thinking about doing the same thing, but thought if I can do it at UI level, it will save me the trouble of writing a complex stored procedure.
Thanks
0
 
UnifiedISCommented:
I think that will do it.  Your stored procedure doesn't need to include any additional logic than is currently being used to provide data.  You just need to add a column which you will populate via your UI.  When you verify your data, populate the FailedData column with some value and you will be able to sort those to the top or bottom using the datagridview's sort method.
0
 
RekhaShahAuthor Commented:
It does not work because, I have all the columns readonly. I added FailedData column to database table. but now during verify process, when I set the checkbox of this column to true, first time it works and then it gives me an error that datareader is already open.close first!
0
 
UnifiedISCommented:
You should close your datareader as soon as you have read your data.  It sounds like you may have to make some other changes to your code as well.  
0
 
RekhaShahAuthor Commented:
Thanks you for your help.
I implemented nested datareader so that going through each row, if i found any invalid data, i could set FailedData field to true. I am posting this comment so that it may be useful to someone else. But inorder to tdo nested Datareaders, I had to set MARS=true in sql connection string. That did the trick.
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now