Hello,
I have a List<MyDataObject> and I want to feed it to an UltraGrid to display (yes, display only, no editing) a row per item of the list. I thought I could just add a few columns and tell the column which member of MyDataObject to display, but it seems it's more involved than that.
Using the grid wizard, I setup a data schema that contains a subset of the public properties of MyDataObject. This creates the columns in the grid as expected. Now, when I set the DataSource to a list of those objects at runtime, the grid is updated to include all the public properties of MyDataObject.
I had to go add all of them in the data schema and then set the column's Hidden property to true for it to work like I wanted. Is there a better way? I have many properties I don't want to display, and I would prefer not having to add each of them to the schema.
Thanks,George Faraj
Hi George,
If the grid is losing the layout you set up at design-time, it means the schema you set up isn't matching the run-time data source. Either that, or you are setting the DataSource property explicitly instead of using the SetDataBinding method and passing in the correct options to hide new columns.
The trickiest part of getting this to work will be the band name. Take a look at the key of the band in the grid at run-time:
grid.DisplayLayout.Bands[0].Key
And make sure you set the key of the band at design-time to the same key you will have at run-time for each band.
Thank you Mike. This worked. (Using SetDataBinding instead of DataSource). Much appreciated.
Hi Mike,
I am trying to do something similar, but I am not being successfull.
I have an object LogEvent defined as:
public class LogEvent{public string Description;public DateTime Time;public string Username;public string Login;public string Machine;public string ThreadId;public bool PmLoaded;public string Odbc;public string Database;public string ErrorReason;public DateTime LastStatusChange;}
I manually set the data binding of my grid to use a list of my LogEvent object as the datasource:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e){OpenLogs(); //Fill EventsListultraGrid1.SetDataBinding(EventsList, "", true);}
I manually created the columns at design time to match the name of the properties of my class.
But still, when I start the application I can't get the grid feeded with data.
Any idea of what is going on would be helpful. I think I set everything accordingly, but I might be missing something?
Thanks,Silas.
Hi Silas,
InitializeLayout fires when you set the DataSource for the grid. So you can't set the DataSource inside that event, because the event won't fire until you set the DataSource. :)
So you need to move your code to someplace else, like the Form_Load.