catlook
February 17th, 2009, 01:33 PM
I have a windows form (not web) application, coded in C#, MS Visual Studio 2005.
I have an Account object ( AcctID -string, AcctName -string, Type -bool, and Date -DateTime). Then I have an ArrayList of Accounts called AllAccounts. In order to display AllAccounts in my datagridview on my form, I convert it to a DataTable and then bind it to the grid. Works like a charm.
However, what I'd really like to do is for the Type column display "red" if false and "blue" if true. And I'd like the Date cell to display blank if the Type is "red".
So, I could make a second object, DisplayAcct, with the same 4 attributes as Account, only all strings. Then I could loop through AllAccounts and build a new ArrayList of DisplayAccounts objects(doing a manually population of each attribute according o my requirements), convert that new list to a DataTable, and bind it to the grid. However, when I want to update an account by selecting it from the grid, I'll have to go back and find the original corresponding Account object. Seems kind of convoluted.
Is there any way to bind my original AllAccounts ArrayList to the grid, but change how the grid displays it? (I know web apps can do this easily, but I haven't found a form app solution).
Thanks for considering this!
I have an Account object ( AcctID -string, AcctName -string, Type -bool, and Date -DateTime). Then I have an ArrayList of Accounts called AllAccounts. In order to display AllAccounts in my datagridview on my form, I convert it to a DataTable and then bind it to the grid. Works like a charm.
However, what I'd really like to do is for the Type column display "red" if false and "blue" if true. And I'd like the Date cell to display blank if the Type is "red".
So, I could make a second object, DisplayAcct, with the same 4 attributes as Account, only all strings. Then I could loop through AllAccounts and build a new ArrayList of DisplayAccounts objects(doing a manually population of each attribute according o my requirements), convert that new list to a DataTable, and bind it to the grid. However, when I want to update an account by selecting it from the grid, I'll have to go back and find the original corresponding Account object. Seems kind of convoluted.
Is there any way to bind my original AllAccounts ArrayList to the grid, but change how the grid displays it? (I know web apps can do this easily, but I haven't found a form app solution).
Thanks for considering this!