I am using a few DataGridViews with BindingSources. One of these DataGridViews is used to display details for a Child Property of another BindingSource.
The child object details are not immediately displayed on the screen (I'm using DevExpress XtraTabControl) and I want to load the child property only when the user displays the tab of that child property.
The child property is retrieved from the database, but as this can take a while it is only loaded the when it is first accessed and subsequent retrievals access the now cached object.
The problem seems to be that creating the BindingSource bindings immediately accesses the Child Property (and therefore accesses the database for every child property, and there are quite a few).
Is it possible to have Child Binding Sources only access the property when it is being displayed?
You can connect your BindingSource to your database at the convenient time, for example when handling the XtraTabControl.SelectedPageChanged or TabControl.SelectionChanged event.
Just set its DataSource property:
myBindingSource.DataSource=myDataSource;
Related
I am working on WPF application, I want create one user control that contain one grid with 5 columns and i want to repeat this control on WPF window form according to data fetched from database. It might be repeat one time or more than one.
the ItemsControl (or List) may help you here. You can bind the ItemsSource Property to your ViewModel IEnumerable Property where your DBEntries are stored.
With the ItemsControl.ItemTemplate Property you can define what DataTemplate is used for each Item of the Enumeration.
KR,
incureforce
I'm currently building an application that utilizes a ComboBox to allow the user to select from a dynamic list of String objects contained within a BindingList object. However, the BindingList is a member of a child class belonging to the main class, which appears to be causing some issues.
When the ComboBox's data source is set initially within the main class via:
this.comboBox.DataSource = this.childClass.dataList;
the contents of the ComboBox appear as expected. However, when the contents of the list changes, the contents of the ComboBox are not updated.
If the BindingList object belongs to the main class, the ComboBox updates without any issues. It would appear that the parent class is not receiving the events that signal that the list has been updated.
Any ideas?
After looking at a similar question I asked (and answered) last year:
Adding/Removing COM Ports from a ComboBox in C#
, it seems I've (re)discovered the solution. The problem was with how the strings were being added to the data source. Because the list was being augmented in another thread, there was an issue with the ComboBox control being updated. By utilizing a delegate and the Invoke() method, the contents of the ComboBox are now updated as expected.
I have a silverlight page which has about 5 user controls. Most of the controls are getting the same data from the database which I wanted to save some round trips to DB. I wanted to get the data in the main page and then pass it to the child controls. I tried creating a public property in the controls and setting them from the main page.
What is the best way of doing this?
Thanks.
From your description, it sounds like data binding would be your best approach (MSDN documentation). If you set the main control's DataContext to the object you retrieved from the database, all of the controls in that page will have access to the DataContext as well. This would also allow you to leverage data binding expressions to populate the properties of the UserControls' children.
I have created an XtraTreeList control that is bound to my bindingSource and it uses a list of custom objects. The MultiSelect property is set to true, so when the user selects multiple nodes I want to define what objects are bound to them. But unfortunately I haven't found any property related to contained data (except the Data which is obsolete and is always null). I also tried to use TreeListNode.GetValue, but it only gives me a displayed value and not the object itself
Is there a way to get access to the object bound to node in XtraTreeList?
The last resort is to use Unbound mode and to create them manually, but I would like to know if there is a simple solution for that
Use the TreeList.GetDataRecordByNode method for this purpose.
I am currently refactoring some of my old code that is pretty terrible. I will have a class that creates a Treeview, populates the node, etc and is displayed on a Winform.
Each node on the Treeview represents some data and when the user clicks on that then a datagridview is also displayed on the Winform. The datagridview will be generated within a new class also.
My idea on this is, when the Winform Loads, create and display the Treeview and use an event to monitor for node clicks. When the Winform handles such an event, then it creates the datagrid object and diplays that.
IS this the best way to architect this?
Thanks.
Yes, what you describe is a standard way to do things in WinForms.
You don't need to create the DataGridView every time though - just place it on the Form and in the event handler load the data from somewhere and change the contents of the DataGridView by assigning to DataGridView.DataSource.
In the form designer, define columns for DataGridView and set their DataPropertyName to the names of the corresponding properties of the data objects in the collection.
Note: the data assigned to the DataGridView.DataSource can be a collection of objects or also a DataTable if you are using ADO.NET to read the objects from a database.
Just use the TreeView.AfterSelect event. It fires anytime the user selects another node, either by keyboard or mouse. Be sure to dispose the old DGV if you replace it completely.