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,
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.
Hi Mike,
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.
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.
Whichever way i go, i can't seem to get things to look how i want.