IListSource Implementation
-
Hi All, I have made a project in VB2008 in which I have bind my Grid to Class as a datasource. The column names of Grid are the property names of the class. But I need to have customize column names for my properties in the Grid. One way is to add an attribute _ for example before each property. But it is so hard to name each and every property as i have thousands of properties in this project. Someone has told me that there is a way by using IListSource.. Does anyone have any idea about that?? Regards Ovais
-
Hi All, I have made a project in VB2008 in which I have bind my Grid to Class as a datasource. The column names of Grid are the property names of the class. But I need to have customize column names for my properties in the Grid. One way is to add an attribute _ for example before each property. But it is so hard to name each and every property as i have thousands of properties in this project. Someone has told me that there is a way by using IListSource.. Does anyone have any idea about that?? Regards Ovais
You could just create the columns in the grid yourself, then just setup the bindings for each column to property yourself.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
You could just create the columns in the grid yourself, then just setup the bindings for each column to property yourself.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...Thanks for your reply dear, but I have only one grid which is binded by different classes at different scenarios.. For e.g. Instead of having separate grids for Employees, Leaves, Allowances, Deductions (to show thier respective detail), i've a single grid. When i hit Employees button, it fills with Employees class, when i hit Leaves button, it fills with Leave class, and so forth.. Hope you understand my problem. Ovais
-
Thanks for your reply dear, but I have only one grid which is binded by different classes at different scenarios.. For e.g. Instead of having separate grids for Employees, Leaves, Allowances, Deductions (to show thier respective detail), i've a single grid. When i hit Employees button, it fills with Employees class, when i hit Leaves button, it fills with Leave class, and so forth.. Hope you understand my problem. Ovais
Ovais Memon wrote:
Instead of having separate grids for Employees, Leaves, Allowances, Deductions (to show thier respective detail), i've a single grid. When i hit Employees button, it fills with Employees class, when i hit Leaves button, it fills with Leave class, and so forth..
Then if you are able to, I would suggest that you have a Form for each category. Apart from this allowing you to do as previously suggested for the column binding, it will enable your users to do side-by-side comparisons between datasets.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
Thanks for your reply dear, but I have only one grid which is binded by different classes at different scenarios.. For e.g. Instead of having separate grids for Employees, Leaves, Allowances, Deductions (to show thier respective detail), i've a single grid. When i hit Employees button, it fills with Employees class, when i hit Leaves button, it fills with Leave class, and so forth.. Hope you understand my problem. Ovais
So what's stopping you from Clearing the Columns collection and creating a new set of columns in the same grid and binding those to the new object collection?
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
So what's stopping you from Clearing the Columns collection and creating a new set of columns in the same grid and binding those to the new object collection?
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...Thats what i was doing so far, but the problem is that i m unable to customize column names in the grid. Acc. to your suggestion, i suppose to name the columns for each class at the time of binding with the grid..
-
Thats what i was doing so far, but the problem is that i m unable to customize column names in the grid. Acc. to your suggestion, i suppose to name the columns for each class at the time of binding with the grid..
Each DataGridViewColumn derivative allows you to set the columnheader text, using it's HeaderText property, seperately from the column name it's bound to.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
Hi All, I have made a project in VB2008 in which I have bind my Grid to Class as a datasource. The column names of Grid are the property names of the class. But I need to have customize column names for my properties in the Grid. One way is to add an attribute _ for example before each property. But it is so hard to name each and every property as i have thousands of properties in this project. Someone has told me that there is a way by using IListSource.. Does anyone have any idea about that?? Regards Ovais
I do exactly the same in my main form, 1 DGV and throw tables at it. I have a static method that formats names according to the capitilasition eg "ContactID" becomes "Contact ID" and I use this to populate the header text, it is part of a method that is used to bind all DGVs and gives me a consistent format throughout the app. It also means you need to take your conventions all the way back to the database design. As I own the DB I have no problem with this. My problem is that if you bind to the List using the public properties you lose the sort/filter capabilities unless you implement iBindingList (I think) on each of your classes which is a PITA. So Ah Ha I though, turn each class into a datatable, at which point I chucked the entire bind to class list out and just bind to the original datatable.
Never underestimate the power of human stupidity RAH