Hi There,
I'm brand new to CSLA, so please forgive my questions.
I am using a ReadOnlyList and a ReadOnlyChild (which I generated using cslagen) classes to fill a datagridview.
My problem is that, although my stored procedure has a given columns order, the datagridview columns appear with a different one. My datagridview.autogeneratecolumns property is set to True.
How can I get the datagridview columns to appear in the same order the stored procedure columns are? Shouldn't it be by default?
Thanks,
I set up my grid once when the form loads.
private
ObjectBindingSource _sessionsBindingSource = new ObjectBindingSource();_sessionsBindingSource.DataSource = _sessions; //_sessions is a BusinessListBase<SessionList, Session>, youmay just want to bind it to a new BusinessBaseList
foreach (PropertyDescriptor prop_descr in TypeDescriptor.GetProperties
(typeof(Session), new Attribute[] { new BrowsableAttribute(true) }))
{
_sessionsBindingSource.BindableProperties.Add
(new BindableProperty(prop_descr.Name, prop_descr.DisplayName));
}
foreach
(DataGridViewColumn c in grdResults.Columns){
c.ReadOnly =
true;c.Visible =
false;}
int colCounter = 0;grdResults.Columns[
"ScheduleGroup_Enrollment_Child_Name"].DisplayIndex = colCounter++;grdResults.Columns[
"ScheduleGroup_Enrollment_Child_Name"].Visible = true;grdResults.Columns[
"ScheduleGroup_Enrollment_Child_Name"].Width = 100;grdResults.Columns[
"ScheduleGroup_Enrollment_Child_Name"].HeaderText = "Child";Rebind it if your source changed
_sessionsBindingSource.DataSource = _sessions;
grdResults.DataSource = _sessionsBindingSource;
This way the order of the columns will be as you want them
Make sure to set them up only once, not every time your source changes
Copyright (c) Marimer LLC