G
Guest
Hi,
I have a List of objects that I would like to display in a DataGrid. The
problem is I don't want to display all of the public accessors, only a few.
However, the default for seems to be for the DataGrid to display everything.
I am unable to assign the DataSource in the designer, I guess because it is
an object, not a DataSet, so I assign programmatically. From my
understanding by creating my own TableStyles and ColumnStyles, then
VisualStudio will not overwrite them with the defaults. This hasn't been the
case for me. This code for constucting the DataGrid and it's Styles.
MyDataGrid.DataSource = MyListofObjects;
DataGridTableStyle MyTablesStyle = new DataGridTableStyle();
MyTableStyle.MappingName = "ArrayList";
DataGridTextBoxColumn MyColumnStyle = new DataGridTextBoxColumn();
MyColumnStyle.MappingName = "MyPublicAccessor";
MyColumnStyle.HeaderText = "MyPublicAccessorName";
MyTableStyle.GridColumnStyles.Add(cs);
MyDataGrid.TableStyles.Clear();
MyDataGrid.TableStyles.Add(MyTableStyles);
I don't know why, but I don't just get the one accessor showing in the
DataGrid, I get a lot more, most of which I don't want to see. I know I
could set their width to 0, but that's just a hack, not a solution.
Although, I would like to just do all of this in the designer, but since I
can't set the DataSource in it, I don't think it would work.
I have a List of objects that I would like to display in a DataGrid. The
problem is I don't want to display all of the public accessors, only a few.
However, the default for seems to be for the DataGrid to display everything.
I am unable to assign the DataSource in the designer, I guess because it is
an object, not a DataSet, so I assign programmatically. From my
understanding by creating my own TableStyles and ColumnStyles, then
VisualStudio will not overwrite them with the defaults. This hasn't been the
case for me. This code for constucting the DataGrid and it's Styles.
MyDataGrid.DataSource = MyListofObjects;
DataGridTableStyle MyTablesStyle = new DataGridTableStyle();
MyTableStyle.MappingName = "ArrayList";
DataGridTextBoxColumn MyColumnStyle = new DataGridTextBoxColumn();
MyColumnStyle.MappingName = "MyPublicAccessor";
MyColumnStyle.HeaderText = "MyPublicAccessorName";
MyTableStyle.GridColumnStyles.Add(cs);
MyDataGrid.TableStyles.Clear();
MyDataGrid.TableStyles.Add(MyTableStyles);
I don't know why, but I don't just get the one accessor showing in the
DataGrid, I get a lot more, most of which I don't want to see. I know I
could set their width to 0, but that's just a hack, not a solution.
Although, I would like to just do all of this in the designer, but since I
can't set the DataSource in it, I don't think it would work.