User (Old forums)MemberMay 3, 2007 at 1:27 pmPost count: 23064
I have one DataGrid control and multiple DataTables that I would like to be shown in the DataGrid. Only one DataTable needs to be presented at any time, so I thought I would have one DataGrid control in my app and change the ItemSource of it when a different DataTable needs to be shown. I did this so I wouldn’t have to go through the additional work of creating new controls and showing/hiding them accordingly. Everything is working out fine, but I wanted to see if there are any reasons to not approach the problem this way. Please let me know if you know of any.
It would also be nice if there was an event I could be notified on when the ItemSource is loaded in the DataGrid so I can change column widths to fit the data. I’ve tried a number of the events in the documentation and I could get any of them to fire when I needed them.
Imported from legacy forums. Posted by Scott (had 2390 views)Xceed SupportMemberMay 7, 2007 at 8:50 amPost count: 5658
There is no reason not to approach the problem this way… It is used by a lot of our users up to now…
Concerning the Notification that the ItemSource was loaded, you can try hooking a value changed handler to the ItemsSource property change notification. ( see DependencyPropertyDescriptor.AddValueChanged() documentation in the SDK ). While I have not tried this approach myself, I think this event could have some chances of success.
Imported from legacy forums. Posted by Marcus [Xceed] (had 277 views)User (Old forums)MemberMay 10, 2007 at 11:37 amPost count: 23064
Great suggestion. I’ve gone ahead and implemented this solution. For those who may ask the same question I’ve attached my source code below.
Create a DependencyPropertyDescriptor for the DataGridControl ItemsSource property:
DependencyPropertyDescriptor gridItemsSourceDescriptor = DependencyPropertyDescriptor.FromProperty(DataGridControl.ItemsSourceProperty, typeof(DataGridControl));
Create a generic EventHandler:
protected void OnDataGridItemsSourceChanged(object sender, EventArgs args)
Connect the two:
Imported from legacy forums. Posted by Scott (had 3445 views)
- You must be logged in to reply to this topic.