View previous topic :: View next topic |
Author |
Message |
EntityDev
Joined: 07 Apr 2016 Posts: 40
|
Posted: Thu Apr 07, 2016 7:31 pm Post subject: Evaluation Questions |
|
|
Hello,
I'm evaluating your VirtualTree for use with Entity Framework 5 using DbContext, VS2010 .Net 4
I note in your samples that the tree easily displays hierarchical data when the child object is of type ArrayList. I believe I also saw in the docs that IList, IBindingList are supported.
What type do you recommend I use for child objects in EF5 so that they can be displayed hierarchically in the tree? Do you have any customers successfully using your grid with any flavor of Entity Framework. If you have any examples, I work in VB.Net.
The default child type in DbContext is ICollection(Of HashSet). I also used ObservableCollection with no luck. The tree shows a .ToString representation of the type, for columns representing children. I also tried emitting the results as IBindingList, IEnumerable and IOrderedEnumerable. None of them displayed as child rows/nodes in the tree.
I loaded data in this manner:
Code: |
Public Sub LoadData()
Using New WaitCursor
Using context = New DispatchMasterBranchContext
context.Customers.Load()
Me.CustomerBindingSource.DataSource = context.Customers.Local
'Me.CustomerBindingSource.DataSource = context.Customers.Local.ToList
'Me.CustomerBindingSource.DataSource = context.Customers.Local.OrderBy(Function(c) c.CustomerName)
'Me.CustomerBindingSource.DataSource = context.Customers.Local.ToBindingList
End Using
End Using
End Sub
|
Thank you.
P.S. I also wonder what the purpose is of the Item column, generated by the tree. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Fri Apr 08, 2016 5:53 am Post subject: |
|
|
If you are using Object bindings then the object returned by the "ChildProperty" must support IList. ICollection is not sufficient since it does not allow Virtual Tree to obtain the item at a given index (or the index for a given item).
If you are having problems binding then I would suggest using Programmatic binding where you can control exactly the data that the tree displays and, if necessary, you can convert data from a collection into and ArrayList or other collection that supports IList. _________________ Infralution Support |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
EntityDev
Joined: 07 Apr 2016 Posts: 40
|
Posted: Fri Apr 08, 2016 12:22 pm Post subject: |
|
|
Thank you for your reply.
I will investigate programmatic binding if necessary, because I like your grid very much, so far.
I am able to tailor the types used in EF easily, and so have modified the code generation template to output classes like these brief examples:
[code]Partial Public Class Customer
Public Property CustomerID As Integer
Public Property AccountNumber As String
Public Property CustomerName As String
Public Property IsActive As Boolean
Public Property CreatedBy As String
Public Property DateCreated As Date
Public Property ModifiedBy As String
Public Property DateModified As Nullable(Of Date)
Public Property DataVersion As Byte()
Public Overridable Property CustomerSites As IList(Of CustomerSite) = New List(Of CustomerSite)
End Class[/code]
I must apologize - it seems the code tag is not working properly. But as you can see, the child property (CustomerSites) now supports IList, yet no child nodes or rows are created in the tree.
Using the above, I load a Customer known to have CustomerSite records. When I iterate over Customer.CustomerSites, I have records.
If ArrayList had a generic version, I'd use it. Even so, List should cover all the bases.
Do you have some idea why this doesn't work for me?
Also, please comment on whether or not you have customers successfully using both Entity Framework and VirtualTree. If you do, please tell me how they're loading up the tree.
Many thanks. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sat Apr 09, 2016 2:10 am Post subject: |
|
|
I'm not sure whether other customers are using Virtual Tree with Entity Framework - certainly I know of others using it with other ORM technologies. There should not be any issue however because Virtual Tree can bind to the classes you posted using standard Object Binding.
What are you setting as the datasource? I assume this is a list of Customer objects. So you need to add an object binding (using the Virtual Tree editor) for your Customer class. Set the TypeName property to the namespace qualified name of the class (eg MyNamespace.Customer) and set the ChildProperty to be CustomerSites. Then select the CellBinding for each of the columns you have defined for the Tree (you must define at least one column) and set the Field property to the property you want to display in that column (for instance CustomerName).
Once this is done Virtual Tree should be displaying the name of each of the customers in the list and where they have child customer sites an expansion icon to display this - to specify the CustomerSite information to display you also need to create an ObjectBinding for the CustomerSite class and in the same way define how its properties are mapped to columns. _________________ Infralution Support |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
EntityDev
Joined: 07 Apr 2016 Posts: 40
|
Posted: Sun Apr 10, 2016 1:43 am Post subject: |
|
|
Thank you for providing some concrete steps.
Yes, I'm setting the DataSource to what is essentially an IList of Customer. CustomerSites is a child property of a type which also implements IList.
I am studying the section of the .chm titled "Data Binding to Object Properties". Using this information and the steps you provided, I'm beginning to see hierarchical display of data in the tree. I've a ways to go, but I'm making progress.
So far I am impressed with the product and the documentation.
Before I spend several days studying the documentation and experimenting, I'd like to ask a guestion:
Is the VirtualTree designed to provide editing, and persiting, in parent and child rows (cells)? I hope that makes sense. More to the point:
1. Does the tree support editing?
2. Can changes be persisted to the bound objects?
3. Can this editing and persistence occur at any level of the tree?
4. Will edits persist to any level in the bound object hierarchy?
I'm sure the answers to one or more of these are probably in your feature list or in the documentation, and I'll discover those as I go, but these came to mind while I was replying. If you don't mind answering them, I'd very much appreciate it.
Many thanks. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sun Apr 10, 2016 4:15 am Post subject: |
|
|
1. Yes Virtual Tree has very flexible editing capabilities - see the section in the help on "Defining and using Editors"
2. Yes - with object binding this works by default by Virtual Tree calling the property setter. You can also programmatically handle binding the data back to your data source by handling the SetCellValue event
3. Yes - you can also define different Editor controls to use for different rows or columns if required
4. Yes again. _________________ Infralution Support |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
EntityDev
Joined: 07 Apr 2016 Posts: 40
|
Posted: Sun Apr 10, 2016 3:26 pm Post subject: |
|
|
Thanks so much for taking the time to answer the questions.
This morning I've been studying the DatabaseBrowser sample and I see there are quite a few editing controls in the columns. I also see sample usage of the SetCellValue event.
And I see in another sample how the GetCellData and SetCellValue events are handled in the case where a column's data must be calculated. This of course may be useful for many other purposes.
I'm now working through the mysteries of the VirtualTree editor. If I set an object datasource for the tree at design-time, VS throws a BindingSource into the mix, which of course becomes the DataSource for the tree. This, in turn, adds an ObjectBinding for the BindingSource.
In the DataSetBrowser sample, I see a CustomerBindingSource set at design-time as the DataSource for the VirtualTree in the DataSetBrowserForm. But on the Data Binding tab of the editor, there is no binding for that BindingSource. My guess is that if it were auto-generated, the sample developer removed it.
So, I have just one question this time: Is it recommended (or valid) that one remove that binding in the editor, and configure the tree using only the class object (business entity) bindings? In the DataSetBrowser sample, I find no event handling for CustomersBindingSource. I suppose that it only exists in the project as a side effect of having set the DataSource for the VirtualTree at design-time.
I ask because I can't find a sample which demonstrates pure object databinding which are non-virtual.
I'm very happy for the four "yes" answers. I'm also pleased to find that the VirtualTree supports IDataErrorInfo and property change notification via IBindingList.
I also note that when I delete a tree from a form, all of the generated ObjectCellBindings, ObjectRowBindings and Columns are properly removed from the designer.vb file. Every time. This is important! There are more than a few controls out there which have a habit of leaving a bunch of orphaned code laying around, including Microsoft's DataGridView. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sun Apr 10, 2016 11:14 pm Post subject: |
|
|
Quote: | So, I have just one question this time: Is it recommended (or valid) that one remove that binding in the editor, and configure the tree using only the class object (business entity) bindings? In the DataSetBrowser sample, I find no event handling for CustomersBindingSource. I suppose that it only exists in the project as a side effect of having set the DataSource for the VirtualTree at design-time. |
As you suggest the BindingSource is only used in the DataSetBrowser sample as a means of setting the DataSource at design time. Virtual Tree actually binds to the default view for the DataTable specified by the BindingSource (in this case Customers table). The Virtual Tree bindings therefore just contain a binding for the customers DataView and another for the customer DataRow. Note that the DataView and DataRow bindings are specific to support for DataSets and if you are not using DataSets then you should either use Object Binding (as per the Simple Tree sample project) or programmatic binding. _________________ Infralution Support |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
EntityDev
Joined: 07 Apr 2016 Posts: 40
|
Posted: Mon Apr 11, 2016 10:53 am Post subject: |
|
|
Thanks very much, noted. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
|