 |
|
 |
Hello,
I'm using your DataTreeView and it's great, but i've found a bug.
If i change the List, so that the ResetList Event is raised the performance decrease after some time. After ca. 7 times changing the Perfomance is down.
If found the problem so you can fix it.
In your Method "ResetData()" you're calling the "WireDataSource()". This Method sets the events, but you don't delete the "old" ones. so after many time changing the List, the ResetList Events and all other are raised many times.
You have to change the WireDataSource Method like this:
this.listManager.PositionChanged -= new EventHandler(this.ListManager_PositionChanged);
((IBindingList)this.listManager.List).ListChanged -= new ListChangedEventHandler(this.DataTreeView_ListChanged);
this.listManager.PositionChanged += new EventHandler(this.ListManager_PositionChanged);
((IBindingList)this.listManager.List).ListChanged += new ListChangedEventHandler(this.DataTreeView_ListChanged);
Then the problem is soled.
Greets Rodion
|
|
|
|
 |
|
 |
I'm using following code in my program, I used dtv1(Datatreeview1) for showing hierarchical relations between my records, i set this code run every time i click a button, for the first time there is no any error and that's work, but when user press button 2nd time, i received this message: Column 'Id' does not belong to table ApprovalTaskData at this line: node.ID = this.idProperty.GetValue(this.listManager.List[position]);
ToDataTable() convert an List to a DataTable
also id is key of ApprovalTaskData table
List list2 = (List)aprService.GetAllRelatedTasksOfDocActionRequest(18);
DataTable dt = new DataTable();
dt = this.ToDataTable(list2);
foreach (DataRow row in dt.Rows)
{
if ((int)row["relatedTaskId"] == -1)
{
row["relatedTaskId"] = DBNull.Value;
}
}
dtv1.DataSource = dt;
anyone know where is the problem?
|
|
|
|
 |
|
 |
This is my code which gives blank tree with no data on it and no errors even.
Dim ds As DataSet = BLModules.GetModuleList
ds.Tables(0).TableName = "Modules"
tv1.FullRowSelect = True
tv1.HideSelection = False
tv1.HotTracking = True
tv1.DataSource = ds
tv1.DataMember = "Modules"
tv1.IDColumn = "ChildId"
tv1.NameColumn = "Title"
tv1.ParentIDColumn = "ParentId"
tv1.ValueColumn = Nothing
tv1.Name = "tv1"
|
|
|
|
 |
|
 |
Please can some body provide me VB.NET Code for WinForms
my data is similar to this database.
please i already wast my three days i stuck on 2nd level i need good general coding.
Thanks
|
|
|
|
 |
|
 |
Here is the code in VB.NET. This is the Jeremy Thomas upgrade version of this control : http://rapiddevbookcode.codeplex.com/SourceControl/changeset/view/63168#945426[^]
Imports System.Collections
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Drawing
Imports System.Drawing.Design
Imports System.Runtime.InteropServices
Public Class DataTreeView
Inherits TreeView
Private Const SbHorz As Integer = 0
#Region "Fields"
Private ReadOnly components As Container
Private ReadOnly mBindingSource As BindingSource
Private listManager As CurrencyManager
Private idPropertyName As String
Private namePropertyName As String
Private parentIdPropertyName As String
Private valuePropertyName As String
Private ReadOnly DataMemberFieldSeperator() As Char = New Char() {"."c}
Private idProperty As PropertyDescriptor
Private nameProperty As PropertyDescriptor
Private parentIdProperty As PropertyDescriptor
Private valueProperty As PropertyDescriptor
Private valueConverter As TypeConverter
Private selectionChanging As Boolean
#End Region
#Region "Constructors"
Public Sub New()
idPropertyName = String.Empty
namePropertyName = String.Empty
parentIdPropertyName = String.Empty
selectionChanging = False
mBindingSource = New BindingSource()
FullRowSelect = True
HideSelection = False
HotTracking = True
AddHandler AfterSelect, AddressOf DataTreeView_AfterSelect
AddHandler BindingContextChanged, AddressOf DataTreeView_BindingContextChanged
AddHandler AfterLabelEdit, AddressOf DataTreeView_AfterLabelEdit
AddHandler DragDrop, AddressOf DataTreeView_DragDrop
AddHandler DragOver, AddressOf DataTreeView_DragOver
AddHandler ItemDrag, AddressOf DataTreeView_ItemDrag
End Sub
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If components IsNot Nothing Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
#End Region
#Region "Win32"
<DllImport("User32.dll")> _
Private Shared Function ShowScrollBar(ByVal hWnd As IntPtr, ByVal wBar As Integer, ByVal bShow As Boolean) As Boolean
End Function
#End Region
#Region "Properties"
<AttributeProvider(GetType(IListSource)), Category("Data"), Description("Data source of the tree.")> _
Public Property DataSource() As Object
Get
Return mBindingSource.DataSource
End Get
Set(ByVal value As Object)
If mBindingSource.DataSource IsNot value Then
mBindingSource.DataSource = value
ResetData()
End If
End Set
End Property
<Editor("System.Windows.Forms.Design.DataMemberListEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", GetType(UITypeEditor)), RefreshProperties(RefreshProperties.Repaint), Category("Data"), Description("Data member of the tree.")> _
Public Property DataMember() As String
Get
Return mBindingSource.DataMember
End Get
Set(ByVal value As String)
If mBindingSource.DataMember <> value Then
mBindingSource.DataMember = value
End If
End Set
End Property
<DefaultValue(""), Editor("System.Windows.Forms.Design.DataMemberFieldEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", GetType(UITypeEditor)), Category("Data"), Description("Identifier member, in most cases this is primary column of the table.")> _
Public Property IDColumn() As String
Get
Return idPropertyName
End Get
Set(ByVal value As String)
If idPropertyName <> value Then
If value Is Nothing Then
DataMember = String.Empty
idPropertyName = String.Empty
Else
Dim split = value.Split(DataMemberFieldSeperator)
Dim temp As String
If split.Length > 1 Then
DataMember = split(0)
temp = split(1)
Else
DataMember = String.Empty
temp = value
End If
idProperty = Nothing
If DataSource IsNot Nothing AndAlso temp <> String.Empty Then
Dim currencyManager = TryCast(New BindingContext().Item(DataSource, DataMember), CurrencyManager)
If currencyManager IsNot Nothing Then
Dim propertyDescriptorCollection = currencyManager.GetItemProperties()
idProperty = propertyDescriptorCollection.Find(temp, True)
If propertyDescriptorCollection.Count = 0 Then
idPropertyName = value
End If
End If
If idProperty IsNot Nothing Then
idPropertyName = value
End If
Else
idPropertyName = value
End If
End If
End If
End Set
End Property
<DefaultValue(""), Editor("System.Windows.Forms.Design.DataMemberFieldEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", GetType(UITypeEditor)), Category("Data"), Description("Name member. Note: editing of this column available only with types that support converting from string.")> _
Public Property NameColumn() As String
Get
Return namePropertyName
End Get
Set(ByVal value As String)
If namePropertyName <> value Then
If value Is Nothing Then
namePropertyName = String.Empty
Else
Dim split = value.Split(DataMemberFieldSeperator)
Dim temp As String
Dim tempDataMember As String
If split.Length > 1 Then
tempDataMember = split(0)
temp = split(1)
Else
tempDataMember = String.Empty
temp = value
End If
nameProperty = Nothing
If DataSource IsNot Nothing AndAlso temp <> String.Empty Then
If tempDataMember = DataMember OrElse DataMember = String.Empty Then
Dim currencyManager = TryCast(New BindingContext().Item(DataSource, DataMember), CurrencyManager)
If currencyManager IsNot Nothing Then
If DataMember Is Nothing Then
DataMember = tempDataMember
End If
Dim propertyDescriptorCollection = currencyManager.GetItemProperties()
nameProperty = propertyDescriptorCollection.Find(temp, True)
If propertyDescriptorCollection.Count = 0 Then
namePropertyName = value
End If
End If
If nameProperty IsNot Nothing Then
namePropertyName = value
End If
End If
Else
namePropertyName = value
End If
End If
End If
End Set
End Property
<DefaultValue(""), Editor("System.Windows.Forms.Design.DataMemberFieldEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", GetType(UITypeEditor)), Category("Data"), Description("Identifier of the parent. Note: this member must have the same type as identifier column.")> _
Public Property ParentIDColumn() As String
Get
Return parentIdPropertyName
End Get
Set(ByVal value As String)
If namePropertyName <> value Then
If value Is Nothing Then
namePropertyName = String.Empty
Else
Dim split = value.Split(DataMemberFieldSeperator)
Dim temp As String
Dim tempDataMember As String
If split.Length > 1 Then
tempDataMember = split(0)
temp = split(1)
Else
tempDataMember = String.Empty
temp = value
End If
parentIdProperty = Nothing
If DataSource IsNot Nothing AndAlso temp <> String.Empty Then
If tempDataMember = DataMember OrElse DataMember = String.Empty Then
Dim currencyManager = TryCast(New BindingContext().Item(DataSource, DataMember), CurrencyManager)
If currencyManager IsNot Nothing Then
If DataMember Is Nothing Then
DataMember = tempDataMember
End If
Dim propertyDescriptorCollection = currencyManager.GetItemProperties()
parentIdProperty = propertyDescriptorCollection.Find(temp, True)
If propertyDescriptorCollection.Count = 0 Then
parentIdPropertyName = value
End If
End If
If parentIdProperty IsNot Nothing Then
parentIdPropertyName = value
End If
End If
Else
parentIdPropertyName = value
End If
End If
End If
End Set
End Property
#End Region
#Region "Events"
Public Sub MoveToItem(ByVal itemToSelect As Object)
If itemToSelect IsNot Nothing AndAlso listManager IsNot Nothing Then
listManager.Position = listManager.List.IndexOf(itemToSelect)
End If
End Sub
Private Sub DataTreeView_AfterSelect(ByVal sender As Object, ByVal e As TreeViewEventArgs)
If Not selectionChanging Then
BeginSelectionChanging()
Try
If e.Node IsNot Nothing Then
MoveToItem(e.Node.Tag)
End If
Finally
EndSelectionChanging()
End Try
End If
End Sub
Private Sub DataTreeView_AfterLabelEdit(ByVal sender As Object, ByVal e As NodeLabelEditEventArgs)
If e.Node IsNot Nothing AndAlso e.Label IsNot Nothing Then
If PrepareValueConvertor() AndAlso valueConverter.IsValid(e.Label) Then
nameProperty.SetValue(e.Node.Tag, valueConverter.ConvertFromString(e.Label))
listManager.EndCurrentEdit()
Return
End If
End If
e.CancelEdit = True
End Sub
Private Sub DataTreeView_ItemDrag(ByVal sender As Object, ByVal e As ItemDragEventArgs)
DoDragDrop(e.Item, DragDropEffects.Copy Or DragDropEffects.Move)
End Sub
Private Sub DataTreeView_DragOver(ByVal sender As Object, ByVal e As DragEventArgs)
Dim tv = DirectCast(sender, TreeView)
Dim position = tv.PointToClient(New Point(e.X, e.Y))
Dim destinationNode = tv.GetNodeAt(position)
tv.SelectedNode = destinationNode
e.Effect = DragDropEffects.Move
End Sub
Private Sub DataTreeView_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs)
Dim dragNode As TreeNode
Dim dropNode As TreeNode
If e.Data.GetDataPresent(GetType(TreeNode)) Then
Dim tv = DirectCast(sender, TreeView)
Dim position = tv.PointToClient(New Point(e.X, e.Y))
dropNode = tv.GetNodeAt(position)
dragNode = DirectCast(e.Data.GetData(GetType(TreeNode)), TreeNode)
If (dropNode IsNot Nothing AndAlso dragNode IsNot Nothing) AndAlso (dropNode IsNot dragNode) Then
ChangeParent(dragNode, dropNode)
dropNode.ExpandAll()
End If
End If
End Sub
Private Sub DataTreeView_BindingContextChanged(ByVal sender As Object, ByVal e As EventArgs)
ResetData()
End Sub
Private Sub ListManagerPositionChanged(ByVal sender As Object, ByVal e As EventArgs)
If PropertyAreSet() Then
SynchronizeSelection()
Else
ResetData()
End If
End Sub
Private handelingItemChanged As Boolean
Private Sub DataTreeView_ListChanged(ByVal sender As Object, ByVal e As ListChangedEventArgs)
If PropertyAreSet() Then
Select Case e.ListChangedType
Case ListChangedType.ItemAdded
Try
If Not IsIDNull(GetCurrentID(e.NewIndex)) Then
If TryAddNode(CreateNode(e.NewIndex)) Then
Trace.Write(e)
End If
End If
Catch ae As ArgumentException
Trace.Write(ae)
End Try
Exit Select
Case ListChangedType.ItemChanged
If Not handelingItemChanged Then
Try
handelingItemChanged = True
Dim changedNode = GetDatasNode(e.NewIndex)
If changedNode IsNot Nothing Then
RefreshData(changedNode, e.NewIndex)
ElseIf IsIDNull(GetCurrentID(e.NewIndex)) Then
Throw New ApplicationException("Item not found or wrong type.")
ElseIf TryAddNode(CreateNode(e.NewIndex)) Then
ResetData()
Else
Throw New ApplicationException("Item not found or wrong type.")
End If
Finally
handelingItemChanged = False
End Try
End If
Exit Select
Case ListChangedType.ItemDeleted
If SelectedNode IsNot Nothing AndAlso ((listManager.List.IndexOf(SelectedNode.Tag) = -1) OrElse listManager.List.IndexOf(SelectedNode.Tag) = e.NewIndex) Then
SelectedNode.Remove()
RefreshAllData(e.NewIndex)
End If
Exit Select
Case ListChangedType.Reset
ResetData()
Exit Select
Case ListChangedType.ItemMoved
Exit Select
End Select
Else
ResetData()
End If
End Sub
#End Region
#Region "Implementation"
Private Sub Clear()
Nodes.Clear()
End Sub
Private Function PrepareDataSource() As Boolean
If BindingContext IsNot Nothing Then
If mBindingSource.DataSource IsNot Nothing Then
listManager = TryCast(BindingContext(mBindingSource.DataSource, mBindingSource.DataMember), CurrencyManager)
Return listManager IsNot Nothing
Else
listManager = Nothing
Clear()
End If
End If
Return False
End Function
#Region "Descriptors"
Private Function PropertyAreSet() As Boolean
Return (idProperty IsNot Nothing AndAlso nameProperty IsNot Nothing AndAlso parentIdProperty IsNot Nothing)
End Function
Private Function PrepareDescriptors() As Boolean
If idPropertyName.Length <> 0 AndAlso namePropertyName.Length <> 0 AndAlso parentIdPropertyName.Length <> 0 Then
Dim propertyDescriptorCollection As PropertyDescriptorCollection = listManager.GetItemProperties()
If idProperty Is Nothing Then
idProperty = propertyDescriptorCollection(idPropertyName)
End If
If nameProperty Is Nothing Then
nameProperty = propertyDescriptorCollection(namePropertyName)
End If
If parentIdProperty Is Nothing Then
parentIdProperty = propertyDescriptorCollection(parentIdPropertyName)
End If
End If
Return PropertyAreSet()
End Function
Private Function PrepareValueDescriptor() As Boolean
If valueProperty Is Nothing Then
If valuePropertyName = String.Empty Then
valuePropertyName = idPropertyName
End If
valueProperty = listManager.GetItemProperties()(valuePropertyName)
End If
Return (valueProperty IsNot Nothing)
End Function
Private Function PrepareValueConvertor() As Boolean
If valueConverter Is Nothing Then
valueConverter = TypeDescriptor.GetConverter(nameProperty.PropertyType)
End If
Return (valueConverter IsNot Nothing AndAlso valueConverter.CanConvertFrom(GetType(String)))
End Function
#End Region
Private Sub WireDataSource()
AddHandler listManager.PositionChanged, AddressOf ListManagerPositionChanged
AddHandler DirectCast(listManager.List, IBindingList).ListChanged, AddressOf DataTreeView_ListChanged
End Sub
Public Sub ResetData()
BeginUpdate()
Clear()
Try
If PrepareDataSource() Then
WireDataSource()
If PrepareDescriptors() Then
Dim unsortedNodes = New ArrayList()
For i As Integer = 0 To listManager.Count - 1
unsortedNodes.Add(CreateNode(i))
Next
Dim startCount As Integer
While unsortedNodes.Count > 0
startCount = unsortedNodes.Count
For i As Integer = unsortedNodes.Count - 1 To 0 Step -1
If TryAddNode(DirectCast(unsortedNodes(i), TreeNode)) Then
unsortedNodes.RemoveAt(i)
End If
Next
If startCount = unsortedNodes.Count Then
Dim AE As ApplicationException = New ApplicationException("Tree view confused when try to make your data hierarchical.")
For Each node As TreeNode In unsortedNodes
AE.Data.Add(node.ToString(), node)
Next
Throw AE
End If
End While
End If
End If
Finally
EndUpdate()
End Try
End Sub
Private Function TryAddNode(ByVal node As TreeNode) As Boolean
If HasParent(node) Then
Dim parentNode = GetDataParent(node)
If parentNode IsNot Nothing AndAlso Not parentNode.Nodes.Contains(node) Then
AddNode(parentNode.Nodes, node)
Return True
End If
Else
AddNode(Nodes, node)
Return True
End If
Return False
End Function
Private Shared Sub AddNode(ByVal nodes As TreeNodeCollection, ByVal node As TreeNode)
nodes.Add(node)
End Sub
Private Sub ChangeParent(ByVal childnode As TreeNode, ByVal parentNode As TreeNode)
If childnode IsNot Nothing AndAlso parentNode IsNot Nothing Then
Dim ParentID = idProperty.GetValue(parentNode.Tag)
If PrepareValueConvertor() AndAlso valueConverter.IsValid(ParentID) Then
parentIdProperty.SetValue(childnode.Tag, ParentID)
listManager.EndCurrentEdit()
Return
End If
End If
End Sub
Private Function FindFirst(ByVal iD As Object) As TreeNode
Dim foundNodes() As TreeNode = Nodes.Find(iD.ToString(), True)
If foundNodes.Length = 0 Then
Return Nothing
Else
Return foundNodes(0)
End If
End Function
Private Function GetCurrentID() As Object
Return idProperty.GetValue(listManager.Current)
End Function
Private Function GetCurrentID(ByVal index As Integer) As Object
Return idProperty.GetValue(listManager.List(index))
End Function
Private Function GetCurrentNodeFromData() As TreeNode
Return GetDatasNode(listManager.Current)
End Function
Private Function GetDatasNode(ByVal dataObject As Object) As TreeNode
Dim dataID = idProperty.GetValue(dataObject)
Return FindFirst(dataID)
End Function
Private Function GetDatasNode(ByVal position As Integer) As TreeNode
Return GetDatasNode(listManager.List(position))
End Function
Private Function GetDataParent(ByVal node As TreeNode) As TreeNode
Return FindFirst(parentIdProperty.GetValue(node.Tag))
End Function
Private Sub ChangeParent(ByVal node As TreeNode)
Dim currentParentID As Object = Nothing
Dim dataParentID = parentIdProperty.GetValue(node.Tag)
If dataParentID IsNot Nothing Then
If node.Parent IsNot Nothing Then
currentParentID = idProperty.GetValue(node.Parent.Tag)
End If
If Not dataParentID.Equals(currentParentID) Then
If HasParent(node, dataParentID) OrElse node.Parent IsNot Nothing Then
node.Remove()
If node.Nodes.Find(dataParentID.ToString(), True).Length > 0 Then
Throw New ApplicationException("A Parent can't be the child of a child!")
End If
Dim newParentNode = FindFirst(dataParentID)
If newParentNode IsNot Nothing Then
newParentNode.Nodes.Add(node)
End If
End If
End If
End If
End Sub
Private Function GetID(ByVal node As TreeNode) As Object
Return idProperty.GetValue(node.Tag)
End Function
Public Sub RefreshData(ByVal node As TreeNode, ByVal Data As Object)
node.Tag = Data
node.Name = GetID(node).ToString()
Try
node.Text = DirectCast(nameProperty.GetValue(node.Tag), String)
Catch e As Exception
node.Text = e.Message
End Try
Me.ChangeParent(node)
End Sub
Public Sub RefreshData(ByVal node As TreeNode)
Me.RefreshData(node, listManager.Current)
End Sub
Public Sub RefreshData(ByVal node As TreeNode, ByVal position As Integer)
Me.RefreshData(node, listManager.List(position))
End Sub
Public Sub RefreshData(ByVal position As Integer)
Dim DataObject = listManager.List(position)
Dim Node = GetDatasNode(DataObject)
If Node IsNot Nothing Then
Me.RefreshData(Node, DataObject)
End If
End Sub
Public Sub RefreshAllData(ByVal fromPosition As Integer)
For i As Integer = fromPosition To listManager.Count - 1
Me.RefreshData(i)
Next
End Sub
Private Sub SynchronizeSelection()
If Not selectionChanging Then
BeginSelectionChanging()
Try
SelectedNode = GetCurrentNodeFromData()
Finally
EndSelectionChanging()
End Try
End If
End Sub
Private Function CreateNode(ByVal position As Integer) As TreeNode
Dim node = New TreeNode()
Me.RefreshData(node, position)
Return node
End Function
Private Function CreateNode() As TreeNode
Dim node = New TreeNode()
Me.RefreshData(node)
Return node
End Function
Private Shared Function IsIDNull(ByVal id As Object) As Boolean
If id Is Nothing OrElse Convert.IsDBNull(id) Then
Return True
End If
If id.[GetType]() Is GetType(String) Then
Return (DirectCast(id, String).Length = 0)
End If
If id.[GetType]() Is GetType(Guid) Then
Return (DirectCast(id, Guid) = Guid.Empty)
End If
If id.[GetType]() Is GetType(Integer) Then
Return (CInt(id) = 0)
End If
Return False
End Function
Private Shared Function ObjectValuesEqual(ByVal object1 As Object, ByVal object2 As Object) As Boolean
Return object1.Equals(object2) OrElse (object1.[GetType]() Is object2.[GetType]() AndAlso object1.GetHashCode() = object2.GetHashCode())
End Function
Private Function HasParent(ByVal node As TreeNode, ByVal parentID As Object) As Boolean
Return Not (IsIDNull(parentID) OrElse ObjectValuesEqual(parentID, GetID(node)))
End Function
Private Function HasParent(ByVal node As TreeNode) As Boolean
Return HasParent(node, parentIdProperty.GetValue(node.Tag))
End Function
Protected Overrides Sub InitLayout()
MyBase.InitLayout()
ShowScrollBar(Handle, SbHorz, False)
End Sub
Private Sub BeginSelectionChanging()
selectionChanging = True
End Sub
Private Sub EndSelectionChanging()
selectionChanging = False
End Sub
#End Region
End Class
|
|
|
|
 |
|
 |
Hi,
This is Sami. As iam new to the .net world. So my requirement is i want to add 4 columns to the griview with different controls in the gridview. i.e.,in the 1st column i want to place the "CheckBox", in the 2nd column "DropDownList with data binding to it", in the 3rd coloumn a "TextBox" and in the 4th column a simple "Text". As i need a full explanation on this with all code.
Please can anyone help me. Its urgent. Waiting for the response.
thanks in advance...
Regards,
Sami.
|
|
|
|
 |
|
 |
Your project does works!!! but I need it to work at the same way but without recursivity... That means that I have more than 1 table I have 3 tables they have a hierarchical topology but I cant make it work with them please help!
Chichuka
|
|
|
|
 |
|
 |
Hello,
i wonder if anybody had this issue with this very good control.
I have a form with a BS that displays some info on it. Also i have a tree that i would want to bound to the same BS. The BS relies on a Self Relation within a Table from a typed Dataset.
Everything works fine until i would want to filter the BS.
I wonder what's the point of allowing the tree to bind to BS if no filtering is supported, being known that the most common scenario used in WIn FOrms is with chained BSs. So, if i have my BS filtered based on a parent table relation, for example, the treeview gets confused. Also if i have an unrelated BS as DataSource, with FIlter property set to some condition.
Please help me with this issue, because i cannot really find anything else that could save me, even if i tried 20 bindable treeviews until now.
PS: I cannot believe that Microsoft are so dumb that they haven't included something for binding to TreeView and ListView being known that they removed the possibility of having hierarchical structures in the DataGrid.
I don't want to wait until 3.0 verion of the framework will b released, so any help would be very appreciated.
Thanks
|
|
|
|
 |
|
 |
for the version I just downloaded, all the files show a last modified date of march 2005.
You mentioned in other messages above that you were going to upload new versions in May and Nov 2005
Do we have the right version?
Thanks for your time and for making this available. Even if I don't use it, I'm learning some things with it.
|
|
|
|
 |
|
 |
Hi All,
I want to hide the hscrollbar in TreeView and VScrollBar still works.
Who can tell me how to do that?
Thanks.
|
|
|
|
 |
|
 |
Hello.
You can find this in code. In short words, it invokes WinAPI method ShowScrollBar(Handle, SB_HORZ, false);.
|
|
|
|
 |
|
 |
Hi there,
I've been trying to track down this problem with the tree control that was stopping me from changing the parent node of another node in the tree. I think I may have fixed it but I was wondering if you could just let me know if this would cause any weird problems..
This is how I set my datasource (the datasource is a Data table):
// Display the categories
m_treeCategories.DataSource = m_dtCategories;
Then to test the changing parent I did this:
m_dtCategories[2].Parent_Cat_ID = 0;
This triggered the ListChanged event in the treeview and I executed this:
case ListChangedType.ItemChanged:
DataTreeViewNode chnagedNode = this.items_Positions[e.NewIndex] as DataTreeViewNode;
if (chnagedNode != null)
{
this.RefreshData(chnagedNode);
this.ChangeParent(chnagedNode);
}
else
{
throw new ApplicationException("Item not found or wrong type.");
}
break;
The changedNode contains the old data for the node (so the ParentID is set to -1(my root)). When you call RefreshData though, it actually sets the node to the new values so ParentID becomes 0. I then have a problem in the ChangeParent function because it fails to move the node to the new parent because of this check:
if (node.ParentID != dataParentID)
They are the same because RefreshData changed them. However if I comment out the call to RefreshData(), it leaves the parentID set to its old value and performs the move.
Is this a sensible fix for me to make?
Also, do you know why the tree control receives duplicate events for the same action.? I am finding when debugging that for example, AddNode sends two events to the list, it doesn't cause a problem but I just wondered why.
Thanks,
Emma
|
|
|
|
 |
|
 |
Hi there,
I am trying to implement drag and drop and I am having problems getting the treenode object that is being dragged..
For some reason it thinks the type is of TreeView when in a drag and drop event, the data should be the TreeNode.. Do you have any ideas why this would happen?
Here's the sample code I am trying to work with..
// It would go into this if block if I set it to DataTreeView...
if(e.Data.GetDataPresent("Chaliy.Windows.Forms.DataTreeViewNode", false))
{
Point pt = ((DataTreeView)sender).PointToClient(new Point(e.X, e.Y));
DataTreeViewNode destinationNode = ((DataTreeView)sender).GetNodeAt(pt) as DataTreeViewNode;
newNode = (DataTreeView)e.Data.GetData("Chaliy.Windows.Forms.DataTreeViewNode");
if(destinationNode != newNode)
{
destinationNode.Nodes.Add((DataTreeViewNode) newNode.Clone());
destinationNode.Expand();
//Remove Original Node
newNode.Remove();
}
}
Many thanks,
Emma Middlebrook
|
|
|
|
 |
|
 |
Hello.
Realy this is too little information to understand your problem.
Things that I am already see:
1) "destinationNode.Nodes.Add((DataTreeViewNode) newNode.Clone());". I am not test this but seems this code will not work (I am sure that I was not implement clone for all data, but possible this is done automatically).
2) Second is that removing of the element possible will remove element from datasource. I can suggest to store ID of the data row not whole tree node.
3) This implementation can not sort. So inserting of the new node will not work properly. I mean that this control use position in the datasource to sort nodes.
In other words I can suggest you to use standard TreeView. Fill nodes from datasourse (you can use code from this one), and then implement drag-n-drop. In this way drag-n-drop will not even try to affect on the datasource.
Thanks.
|
|
|
|
 |
|
 |
Hi,
Thanks for the reply, I had a feeling this wouldn't work. I'd rather continue to use your tree control because my main requirement was having bound data to the treeview control. I think I am going to disable the drag drop ability and have a separate dialog to manage the nodes in my tree to let the user edit, remove and add through the application.
Thanks
Emma
|
|
|
|
 |
|
 |
I have modified the control to handle Drag and Drop if anyone is interested.
|
|
|
|
 |
|
 |
Hi,
I'd be interested in a version of this control that implements drag and drop.
Emma
|
|
|
|
 |
|
 |
Jeremy
I'm interested. I've modified the control to include images (nothing like the changes I'm sure you've made, but I'd be glad to share).
Jay Smith
SmithSystems
Jeremy Thomas wrote: ForumHierarchical TreeView control with data binding enabled
Subject:Re: Implementing Drag and Drop
Sender:Jeremy Thomas
Date:22:02 13 Feb '06
I have modified the control to handle Drag and Drop if anyone is interested.
|
|
|
|
 |
|
 |
Hi,
Thanks for posting your response. I am interested in drag n drop.
can u please share that with me.
Cheers
|
|
|
|
 |
|
|
 |
|
 |
Very cool... keep updating us n the progress
|
|
|
|
 |
|
 |
if you add a new row in the list of datasource,and if you don't add in at the end of list,then many position in nodes will be error;and there's the same error with items_Positions.
so , I think you could remove items_Positions,using Find to locate the data for node. but I know it's very slowly
or you must caculate postion again when the delete data or add data.
I couldn't visit your homepage,why?and how can i cantact you?
|
|
|
|
 |
|
 |
Hello.
Sorry but I can not reproduce this. If this is not a problem please send test code.
Thanks.
|
|
|
|
 |
|
 |
I have a custom collection, "DogCollection”, which inherits CollectionBase. When I am trying to set this collection as the TreeView's DataSource, the following exception is thrown:
$exception {"Cannot create a child list for field DogCollection." } System.ArgumentException
This happens in the PrepareDataSource() at this line:
this.listManager = this.BindingContext[this.dataSource, this.dataMember] as CurrencyManager;
|
|
|
|
 |
|
 |
Hello.
Please implement IBindingList interface in your connection. Of course if this is possible. In few days, I will upload new version that will check for this.
Thanks.
|
|
|
|
 |