Below is a stripped out version of my object...
public class OffLineFolder { private string _offlineFolderFriendlyName; private string _offlineFolderActualName; private BindingList<OffLineDBFile> _offlineFileList; private BindingList<OffLineFolder> _offlineSubFolder;
public string OfflineFolderFriendlyName { get { return _offlineFolderFriendlyName; } set { _offlineFolderFriendlyName = value; OnPropertyChanged("OfflineFolderFriendlyName"); } }
public string OfflineFolderActualName { get { return _offlineFolderActualName; } set { _offlineFolderActualName = value; OnPropertyChanged("OfflineFolderActualName"); } }
public BindingList<OffLineDBFile> OfflineFiles { get { return _offlineFileList; } }
public BindingList<OffLineFolder> OfflineSubFolder { get { return _offlineSubFolder; } }}
What i would like is to have the following structure displayed...
\\mydomain1\myshare1\myfolder1
subfolderA
subfolderB
sub-subfolder1
sub-subfolder2
subfolderC
\\mydomain2\myshare2\myfolder2
So, the OfflineFiles list property would always be hidden. The OfflineFolderFriendlyName would always be the display text. And i do not want to show a node for the property OfflineSubFolder - just the subfolder items themselves.
I have played around with various options on the treeview but i just cant get it to look how i describe above. I could get it to show how i want it by creating the nodes manually but ideally i'd like to it through databinding.
Could someone please guide me in the right direction?
Thanks
Danial
Hi Danial,
If your node is displaying columns, then the Image property on the node appearance will not work. Node images are only supported for Standard-style nodes that are just showing a string. To add images to a grid-style node with columns, you have to put the image inside a column. So you could add a column to your ColumnSet and display the image in the cell.
Hi Mike,
In the process of putting together a simple project outlining my problem, i found a few bugs in my code! :-)
So now using ViewStyle = Standard, i get pretty much what i'm looking for. The only minor problem remaining is the icon images are not appearing next to the nodes despite being setup in the columnsets. If i change ViewStyle = FreeForm then the icons appear. BUT the problem with ViewStyle = FreeForm is that the columns are cutting off the text. i.e Not Auto Sizing.
I can get around this by changing ViewStyle back to Standard and checking the object type in the InitializeDataNode and setting the node image from there, but it would be nice to know how to auto size the columns in FreeForm. Is this possible?
dannyh246 said:In the code i originally posted for the class definition for OfflineFolder both lists are null as you point out...however in the full version of the code, OfflineFiles is set to a new empty list, but OfflineFolder is set to null. The reason for this was, as it has a child object of itself i was worried about it recursively generating new instances when i instantiate the object?? Or do i not need to worry about that?....I guess i can test that part out.
This is not a big concern. The tree only creates 2 levels initially - the root level and then one level down.
dannyh246 said:In the full application, on the left hand side of the screen i want to show a tree bound to the ParentList object, this is where i want the offlinefiles hidden, but on the right hand side i want to show another tree that is bound to the OfflineFolder they clicken on from the left. So i dont think i can use the [Browsable = False] attribute as it will then be hidden in the tree on the right.
Okay, that makes sense.
dannyh246 said:How do you get the NodeText to be the objects FriendlyName property? When i use ViewStyle = Standard, and i set the NodeTextColumn to be FriendlyName, it works for the first level, but further levels down the tree revert back to showing ActualName.
If you are allowing the tree to automatically create the ColumnSet, then there will be a new ColumnSet for each level of the data that has a different name. So it may be a new ColumnSet on every level or it might just be two ColumnSets: one for the root and one for all of the child bands. So the way to handle this it so trap the ColumnSetGenerated event and make sure you set the NodeTextColumn on all of the ColumnSets that are applied to that band at every level.
dannyh246 said: I cant work out which ViewStyle would be best. By using standard i've got it to look the closest to what i'm after, but still i need to work out how to hide OfflineFiles, hide the column header for OfflineFolder (but still show the actual folders themselves), and get lower levels to show FriendlyName property. If i use ViewStyle = Default, before i even get started the text of the nodes get cut off, and despite setting various resize options i cant seem to get the columns to resize.
I cant work out which ViewStyle would be best. By using standard i've got it to look the closest to what i'm after, but still i need to work out how to hide OfflineFiles, hide the column header for OfflineFolder (but still show the actual folders themselves), and get lower levels to show FriendlyName property.
If i use ViewStyle = Default, before i even get started the text of the nodes get cut off, and despite setting various resize options i cant seem to get the columns to resize.
I'm having a really hard time envisioning what you want and imagining how this data source matches up to it. Could you create a small sample project using a true representation of your data source with some fake data in it and bind it to a tree control in a sample project and post it here? Then I could play around with it and see what's actually happening and help you achieve what you want.
Thanks for the response.
No, im actually binding to an object something like below. (I left it out to try and simplify.)
public class ParentList { private BindingList<Workstation> _workstationList = new BindingList<Workstation>(); private BindingList<SQLServer> _sqlServerList = new BindingList<SQLServer>(); private BindingList<OffLineFolder> _offlineFolderList = new BindingList<OffLineFolder>();
public BindingList<Workstation> Workstations { get { return _workstationList; } }
public BindingList<SQLServer> SQLServers { get { return _sqlServerList; } }
public BindingList<OffLineFolder> OfflineFolders { get { return _offlineFolderList; } } }
In the code i originally posted for the class definition for OfflineFolder both lists are null as you point out...however in the full version of the code, OfflineFiles is set to a new empty list, but OfflineFolder is set to null. The reason for this was, as it has a child object of itself i was worried about it recursively generating new instances when i instantiate the object?? Or do i not need to worry about that?....I guess i can test that part out.
In the full application, on the left hand side of the screen i want to show a tree bound to the ParentList object, this is where i want the offlinefiles hidden, but on the right hand side i want to show another tree that is bound to the OfflineFolder they clicken on from the left. So i dont think i can use the [Browsable = False] attribute as it will then be hidden in the tree on the right.
How do you get the NodeText to be the objects FriendlyName property? When i use ViewStyle = Standard, and i set the NodeTextColumn to be FriendlyName, it works for the first level, but further levels down the tree revert back to showing ActualName.
Whichever way i go, i can't seem to get things to look how i want.
There are a couple of ways you could achieve this. How you do it depends on the needs of your application. But there are some issues with your data source that you should work out first.
I am assuming you are binding the tree to a BindingList<OffLineFolder>. Is that correct?
The way you have it set up now, OffLineFiles and OfflineSubFolder will initially return null. OfflineFiles doesn't really matter, since you want to hide it anyway, but OffLineSubFolder will be a problem, because the DotNet BindingManager will be unable to determine the data structure if the property returns null. So you should make these properties lazily-created and return an empty collection and never null,
To hide the OffLineFiles, you have two options. You could put a [Browsable(false)] attribute on the property. This will hide this property from DataBinding in general, as well as from the property grid (which probably doesn't matter).
The alternative is to hide the column in the tree. Every property on your object will be a column in the ColumnSet that the tree creates to represent your data structure. So you could handle the tree's ColumnSetGenerated and set the Hidden property on the OfflineFiles column. Or even remove the column entirely, if you want.
OfflineSubFolder is showing a band node because you have two sibling child bands in your data source (OffLineSubFolder and OffLineFiles). Hiding the OffLineFiles should alleviate the need for that extra node. If you hide OffLineFiles on the data source, it shouldn't be a problem. If you hide it in the ColumnSetGenerated event, I think it will still work, but I am not 100% sure - there might be an issue of timing there.