How to bind the data in treeview with sqldatasource - c#

I have data in following two tables
Parent Mater and Child Master
In parent master there are two fields prtID and name. In child master there are three fields ID, name and prtid, The prtid is foreign key from parent master.
I want to bind data with TreeView in a windows application in c#.net
such that each child will appear inside its parent node.
Can please guide me to right direction for this task?

Looks like duplicate entry. Please do some search before making a new question :
Bind C# Windows Form TreeView from DataBase

Related

How do you handle a Master-Detail window with EntityFramework?

This is a problem that I couldn't find any trivial solutions besides that it is so common. I think the question is abstract enough to apply to both WPF and Winforms
Do you allow inserting childs if the master is still not saved?
This forces us to have an in-memory collection of items and to save the master and then the childs when the user hits the save button
What happens when deleting a child from an existing master?
If the user enter to a window for editing a master entity that have some childs, the deletion of a child should be done immediately or it should have an in-memory collection of deletes that its replicated when the user hits the save buttons.
This further complicates the problem because the program should manage the case when the user add a new child and then delete it, as this child doesn't exist on the database it shouldn't be added to the deletes list
What happens if a child entity is have its own children that can be edited?
If a master-detail view allow to edit the detail entities, and the edit window for this entities is another master-detail view, the save button if the inner child alters the database or somehow the save is delayed until the master save button is clicked
Do you insert a dummy empty master to make the logic easier?
I think is easier to insert an empty master entity when first creating one and that all CRUD operation over the master children affect directly the database on the newly created entity and if the cancel button is hitted, just delete the master and all its children. Does anyone have already done this?
The problem that I see here is that some tables have required values or foreign keys that can't just be assigned with a default value
This would be solved if the program didn't allow the user to add children entities until the user have saved the header data of the master detail window

hierarchy parent child relationship datagrid C# window application

I want to create hierarchy parent child relationship datagrid C# window application
using collapsible-rows-in-datagrid
but now i want to add Add Edit Image In this Grid like
please advice for this
DataGridView doesn't directly support row expanding/collapsing, see this post.
Although following trick doesn't seem robust to me, you can use filtering by a hidden column to emulate row collapsing/expanding. To make a +/- sign you can engage DataGridViewCheckBoxColumn with custom check images.
Once user checks/unchecks a cell in this column, you can traverse all children of the affected row and update the hidden column value to show or hide them.
By comparison with master/detail approach this trick allows to show deep hierarchies.

Adding Data grid view as a child node in a Tree View

Basically, I'm working on a winforms application. Now I'm stuck in a problem in which I want a tree grid view that displays nodes in DataGridView. I already used customized DataGridView that that displays child nodes. But what I want is to add another DataGridView in a child node. Meaning, when a user expands a node, a data grid view displays as a child node. Please help me.
Have a look at the following code project article in which a Dropdown box is added as a treenode item. The article extends the TreeNode and adds a ComboxBox. It should be fairly simple to extend to a DataGridView
http://www.codeproject.com/Articles/14544/A-TreeView-Control-with-ComboBox-Dropdown-Nodes

Custom Query Dynamic Data Application

I am trying to use a Dynamic Data Application and having issues with customizing a query. Everything scaffolds wonderfully, however, I want to be able color code the main Parent table when a Child Objects Property is a certain value. Normally I would just iterate over the data using LINQ however, all the information I've researched always filters and color codes items in the grid based on the Parent level data. Any ideas on how to do this on Child Data?
In the ItemDataBound event of the child control, if the condition is met, you can walk up the control hierarchy recursively until you reach the row/item of the parent grid. Once you get to the row/item, you can set the color to whatever you need.

Silverlight -Pass Data from a parent to the child controls

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.

Categories