Hi all, I'm wondering if someone can tell me how to dynamically associate a field in an UltraGrid with a group defined in the UltraGrid?
I am using Progress OpenEdge 11.2 with the 11.2.20112.2124 version of the control, and I can add the group and fields to the group at design time using the UltraGrid designer. But I'd like to be able to do this at runtime, so that I can associate the fields to different groups. Does anyone know if this is possible? I can create the groups dynamically, but how can fields be added to them?
Thanks,
Paul.
Hi Michael,
Thanks for the example. I was using an OpenEdge proBindingSource object as the data source. But once I got my head around how to convert your example to OpenEdge ABL I was able to get it to work. Thanks a lot for the help. I appreciate it.
Hello Paul,
In most test samples I bind the grid to a data table.
private DataTable GetEmployeeOptions() { DataTable dtData = new DataTable("EmployeeOptions");
dtData.Columns.Add("ContactName", typeof(string)); dtData.Columns.Add("EmployeeID", typeof(int)); dtData.Columns.Add("Option", typeof(string)); dtData.Columns.Add("Description", typeof(string));
for (int i = 0; i < 96; i++) { dtData.Rows.Add(new object[] { i, i % 24, string.Format("Option {0}", i), String.Format("Option Description {0}", i) }); }
dtData.PrimaryKey = new DataColumn[] { dtData.Columns["OptionID"] };
return dtData; }
//Bind data in event, eg. Form_Load
this. ultragrid.datasource = GetEmployeeOptions()
Let me know if you have any questions regarding this matter.
Thank you for the code. Correct me if I'm, wrong, but in your example the columns are already added to the band, right? i.e in the line:
group1.Columns.Add( band.Columns["ContactName"], 0, 0 );
The "ContactName" column has already been added to the band? Do you have code showing how adding the column to the band can be done?
thanks,
The Groups collection off of the UltraGridBand exposes an Columns.Add you can use to add columns.
Like so,
UltraGridBand band = this.ultraGrid1.DisplayLayout.Bands[0]; UltraGridGroup group1 = null; // Add group group1 = band.Groups.Add( "Group1", "Contacts" ); // Add column "ContactName" to the first level (level 0) of group1 with visible // position of 0 (meaning it will appear first in that level.) group1.Columns.Add( band.Columns["ContactName"], 0, 0 ); // Add City column to second level (level 1) with visible position of 0. group1.Columns.Add( band.Columns["City"], 0, 1 );
UltraGridBand band = this.ultraGrid1.DisplayLayout.Bands[0]; UltraGridGroup group1 = null;
// Add group group1 = band.Groups.Add( "Group1", "Contacts" );
// Add column "ContactName" to the first level (level 0) of group1 with visible // position of 0 (meaning it will appear first in that level.)
// Add City column to second level (level 1) with visible position of 0.
group1.Columns.Add( band.Columns["City"], 0, 1 );