DataGrid, binding to Collection
-
First of all, I'm kind of a n00b on C# (only been at it for 3 months on and of now..) I'm trying to bind a DataGrid to a collection (that is strongly typed, has IBindingList etc. implemented), but I don't want all fields shown (like Id, InsertTime, updateTime etc.) I've 'been looking all over the internet but can't find anything about the subject, everything I find is about DataTable/DataSets, or about ASP.NET, where the DataGrid has an AutoGenerateColumns boolean that you can set to false. Does anyone here have an example I could look at?
-
First of all, I'm kind of a n00b on C# (only been at it for 3 months on and of now..) I'm trying to bind a DataGrid to a collection (that is strongly typed, has IBindingList etc. implemented), but I don't want all fields shown (like Id, InsertTime, updateTime etc.) I've 'been looking all over the internet but can't find anything about the subject, everything I find is about DataTable/DataSets, or about ASP.NET, where the DataGrid has an AutoGenerateColumns boolean that you can set to false. Does anyone here have an example I could look at?
Create you own DataGridTableStyle and map it to your datasource. Then create GridColumnStyles for each field you want to display, and add them to your DataGridTableStyle. Finally add the DataGridTableStyle to your DataGrid. If you get the mapping right (which can be a little tricky!) it should display your TableStyle and only the columns you added to the TableStyle.
-
Create you own DataGridTableStyle and map it to your datasource. Then create GridColumnStyles for each field you want to display, and add them to your DataGridTableStyle. Finally add the DataGridTableStyle to your DataGrid. If you get the mapping right (which can be a little tricky!) it should display your TableStyle and only the columns you added to the TableStyle.
Just found it out myself :-D. If you create the GridStyle, you have to set it's mappingname to the type of your Collection, so if your collection is of Type CompanyCollection, that should be the mappingname. Tricky indeed...
-
Just found it out myself :-D. If you create the GridStyle, you have to set it's mappingname to the type of your Collection, so if your collection is of Type CompanyCollection, that should be the mappingname. Tricky indeed...
partyganger wrote: Tricky indeed... What I meant is that (IMHO) it doesn't parallel what you do with a dataset. In a dataset you give it the name of the table, so (again IMHO) with a collection you might expect to give it the name of that instance of the collection or maybe the name of a property in your class (if you class wrapped a collection), but you don't, you give it the name of the type of the collection (as you rightly pointed out). That seem counter-intuitive to me and it also means that you can't switch a datagrid from binding one collection object to another collection object of the same type and expect it to automatically switch styles (because they'd both use the same mapping). Sheez...sorry I bothered :~