Hi all,
I am working on a piece of code that should be able to display a set of data which is unknown on compile time: meaning I want to execute SQL statements, without knowing the model before execution.
Since the rows are in my case returned as object arrays (due to a generic transport model), I have to bind them at runtime.
This is the code I use for the moment:
List<UltraGridColumn> columns = new List<UltraGridColumn>(); int i = 0;
foreach (string entityField in actionTable.FieldDefinitions) {UltraGridColumn column = new UltraGridColumn(entityField, i++); column.Header.VisiblePosition = i;ultraGrid1.DisplayLayout.Bands[0].Columns.Add(column);}
this.ultraGrid1.DataSource = actionTable.Result; // this is an object array.
In the InitializeLayout event I try the following:
UltraGridColumn column = this.ultraGrid1.DisplayLayout.Bands[0].Columns["fieldName1"];
if (column.Editor == null){//execute some code}
Then at the line with the "if (column.Editor == null)" a NullReferenceException is thrown. Does anyone have a clue why?
Thanks Mike, I reported the feature request. Thanks for your help.
Hi Patrick,
The grid doesn't always deal with a BindingSource, it typically only deals with IList or IBindingList and neither of these have a DataSourceChanged method or event. I suppose that the grid could special-case for the BindingSource, though. So if you would like to submit a feature request for this, I encourage you to do so:
Submit a feature request to Infragistics
Hi Mike,
When you say: "it updates every time the grid's DataSource ... property is set" you are right, and that is the whole problem, because when you use an intermediate datasource object, such as the BindingSource, it gets called once, at the time the assignment the BindingSource is called.
I guess you can fix this when you hook on the DataSourceChanged property at the time you assign a BindingSource to the DataSource of a grid. You can unregister at the moment the DataSource is being set to something else. When you handle the event, just raise the InitializeLayout event, just like you do when setting the DataSource property of your Grid.
Does this sound like a appropriate enhancement request?
Thanks,
Patrick
Hi Patrick.
patrickhofman said: This event never gets raised when I use a BindingSource to bind to the Grid, when binding directly to the grid using the DataSource property it does get raised. Can you explain how to get this method raised when using an intermediate datasource?
This event never gets raised when I use a BindingSource to bind to the Grid, when binding directly to the grid using the DataSource property it does get raised.
Can you explain how to get this method raised when using an intermediate datasource?
This is simply not true. The InitializeLayout event of the grid fires any time the grid's DataSource or DataMember property is set, or when you call SetDataBinding. The event may not fire if you set the property to what it was already set to, of course.
If the event is not firing, then something else is wrong. Perhaps you are not hooking the event at the property time, before the DataSource is being set.
I had like to refer to http://community.infragistics.com/forums/p/7306/62349.aspx#62349 where you state that you should call another method to refresh the grid's data.
The fact is that the data in the grid does get refeshed, but not the layout.
Please explain how to fix this (I suppose this to be a bug).