I can't find an example of a silverlight 2 tree control that is bound to a database table. I have a table with ID and ParentID columns and I use it to populate a tree control in windows forms. I want to do the same with a silverlight tree control but I can't find any examples on how to do this. Most of the samples have the nodes hard coded. I don't need any advice on how to wcf the data table, I know that part really well. Thanks in advance.
I have not worked with the tree control myself, but I did a quick google, and found the following site Populating Silverlight TreeView from WCF Service with LINQ to SQL
It does however make use of custom classes to store the data and then makes use of LINQ to SQL to extract data from your data tables to manually construct the tree view.
Hope this helps
Related
I am a newbie to WPF. The question is about displaying a tree structure in WPF.
I have a WPF app, which will connect to a remote database. One table (Taxonomy table) in the DB has two columns: "Parent node" (varchar(50)), and "Child node"(varchar(50)). Now I want to display that phylogenetic tree (as shown in the pic). Each nodes on the tree is coupled with a checkBox, and therefore, the user is able to select multiple nodes as they need.
Due to lack of knowledge in WPF, I really have no idea how to achieve that. What controls (or combination of controls) should be used here? Is WCF necessary in this case?
Thanks in advance.
Any suggestion or tutorial is greatly appreciated.
Trying to create what i feel should be an easy WPF application. basically what i want it to do is have a autocomplete combobox which is bound to a sql db table. the table has 2 fields(Address and Directions)
once the user selects the record from the address combox the directions textbox below will be filled directions stored in the table.
if there are no records in the address combobox the user can then type in the combobox and add the new entry.
there will be a save button on the form that saves the new entry and will be visible in the list. Im new to WPF applications and have been trying to get this to work for weeks. Any help would be appreciated.
I would start by checking out the following discussion which will point you to several good tutorials on using the MVVM (Model-View-ViewModel) pattern with WPF.
MVVM: Tutorial from start to finish?
Other than that, you haven't really given any indication what you've tried and what isn't working so I can't really offer any other advice. But even the simplest applications in WPF are much cleaner and more easily implemented with MVVM than using code behind and drag and drop data binding.
I am using a WCF service reference in a WPF project, and my entity framework data model resides in WCF project.
And I am using MVVM Light framework. I am doing the following things:
I use LINQ in the service to get data and then fetch it from WPF, obersvablecollections usually.
Everything works in view part like populating datagrid, views as required.
But I have following doubts:
Is this correct way of transferring data between wcf and wpf.
I haven't used the Model for anything yet, I have doubt about when to use it?
I also wanted to save data from datagrid. I was able to pass on the observablecollection of updated data of datagrid to the service's function. But how do i update the entity from this collection? by looping? doesnt sound right. Once I update the entity from this collection I will be able to use saveChanges to update into database.
When I need to show hierarchal data in a treeview, where to make that data hierarichal, from stored procedure xml? use a view to create a grouping criteria column? create this column in service? create this column/property in presentation?
1 - There is no correct way, it depends on your requirements and goals.
2 - With MVVM, the model should sit between WPF and the database. That means all calls to the database should go through the model, and all writes to the database should also go through the model. The WPF GUI should only bind to the model. This usually means that your WPF portion consists mostly of XAML code. All code that accesses the database should be in the model.
There are good reasons for separating this.
You can write unit tests that on the model.
The view model is independent from the look of the GUI. This means that you can easily change the GUI by dropping in different components and just binding to the model.
A quick google search can probably yield more reasons.
3 - I would try to send over only the entities that have changed. This can be done by passing the collection to your view model, and have your view model figure out what has changed.
4 - I don't quite understand what you want to do. Usually, to make a TreeView, you should create HierarchicalDataTemplate for each of your view models. The TreeView control will take care of the rest. You should really do some tutorials on this one, because it's kinda hard to wrap your head around.
In looking through samples I have seen a number of examples where it is possible to present data within a wpf applicaiton by binding to collections. However I was wondering is it possible to write to a collection from an applicaiton. Say for example i have 2 or more fields such as names and I wanted to have hte ability to add up to three names in my application ( all stored in memory). Will collections serve this purpose. In the past with asp.net I have done this by creating data tables and storing values on the fly or during the session. I am trying to learn WPF and I was wondering if collections work in the same fashion?
If so could you please post an example or point me to references that show examples of this?
Thank you in advance.
Use ObservableCollection as a datasource if you want UI to update on the changes you made to collection from your code.
See ObservableCollection<(Of <(T>)>) Class It also contains quite a good sample.
I'm using winforms. I spend a lot of time drawing forms (maybe not a lot, but it is a boring task).
To sum up... I want to develop a simple aplication that connect to a sql server database, let the user to select a table, and put the controls in a form for me (generate the designer code), based on the tipe of each column. Then my app will name each control like the column of the table, set the maxlengh property (if the type is varchar), and create a label with the same text near the control. If the column is a FK, then the app will draw a combobox and so on. I saw that Telerik Open ORM make something like this, but I only need a simple app for the IU Generation.
If the same day I finish my little application I discover a tool that make the same... I will feel myself stupid :D
Are there any tool out there that do this work for me?
You can just drag DB columns from the Server Panel and drop them on the Form. This will generate TextField, CheckBoxes and other UI elements for you.
You can also drag the entire table and drop it on the form. Same thing will happen: all fields will get generated.
This is using plan Visual Studio 2008 IDE.
Take a look at DevExpress - they have a number of ways to do exactly this. (We're a happy user of their product.)
Take a look at Microsoft lightswitch. I had posted a similar question as yours and stumbled upon it by accident. Devexpress also has an orm like Teleriks http://www.devexpress.com/Products/Index/Frameworks.xml. I am using Lightswitch for form gen. good luck