I am using a Windows Forms TreeView control in my program. I would like to allow the user to select multiple nodes at the same level by dragging their mouse pointer around (also called a "lasso" selection). I don't think a standard TreeView allows that.
My question is what would be the best way to achieve this? Do I have to write custom selection behaviour of my own in perhaps a custom or derived control? Where do I start?
I don't need a detailed explanation. Just a small nudge in the right direction.
This is not going to be easy to do with a standard WinForms TreeView control. The TreeView control only supports single selection per tree. It is not possible to simultaneously select multiple nodes in the tree.
In order to get this behavior you would likely end up needing to create a very similar class to TreeView which allowed for multiple selection. Another option is to derive from TreeView and enable multiple selection by overriding specific behaviors. Here is an article on how to do the latter.
http://www.arstdesign.com/articles/treeviewms.html
Consider implementing multiple selection in a control that supports multiple selection like listview. If you follow standards that most Windows users understand you'll end up with a solution that is easier to implement and easier to use.
If you really need something more elaborate you might need to consider developing a custom control.
Related
I am doing my first steps programming a little toolbox in C#.
I want to choose the program to run via a menustrip.
How can I switch all visible textboxes, buttons etc. on the same form? I don't want to open a new form. Do I have to show/hide every element "by hand" or is there a better solution?
I hope you get my problem.
Thanks in advance.
Yes totally understood.
You need a way to navigate between different fragments within your application.
Since these are your first steps and not a legacy app, why aren't you starting with WPF which is the successor of Winforms ? (newer better)
See how can you achieve such functionally in WPF
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/app-development/navigation-overview?view=netframeworkdesktop-4.8
Although the terms are similar and also apply in winforms.
What you want to do is to create all the buttons etc as part of a UserControl. You can then add your custom UserControl to the form. This should allow you to switch the user control for some other control, or change the visibility for the whole user control.
This can also allow you to place multiple user controls side by side or in some other layout.
I have a winforms tab control which has several tab pages. Within each tab page controls (textboxes, radio buttons, etc...) are group into groupboxes. These group boxes are arranged from top to bottom but in some occassions some groupboxes needs to be visible and other ones to be hidden. Also control within each group box sometimes (depending on the scenario) needs to be visible and sometimes hidden. So I would like to know if someone knows a good approach to do this, maybe some kind of pattern if any. Also it would be good to implement a generic solution to do this. Could any expert in GUI guide me in the right direction to do this?
Using C# and dot NET Framework 4.0, WinForms. This is a desktop application, not Web-based.
You can define the scenarios in a class then add another class that will manage the layout by reading the scenario and laying the elements based on the scenario. I have not provided details because it varies on how specific you want to be and what behavior you want to achieve. It is better to put the Widgets inside a User Control and let that user control communicate with the layout manager.You can use the Mediator pattern or variation of it to coordinate between the widgets. Hope this helps.
I usually try to group related controls into UserControls (even if this means doubling up on some controls) and adding them to or removing them from the form as needed. An example of this could be payment methods - when the user selects a specific payment method (Credit Card, Cash, Cheque, etc) a UserControl with the correct elements is displayed within a panel on the form.
A good pattern to use when managing this sort of set up is Model-View-Presenter, in the example, all the UserControls would probably implement an IPaymentMethod view interface and provide a way to update the corresponding models.
I'm building a windows form for access control in our system. The TreeView control is perfect since everything can be (and should be) presented in a form of a tree. There should be several tree views (users & user groups, user groups & roles, roles & permissions, ...) and handling of access control is envisioned as drag&drop operation between these treeviews.
There is a caveat, which is a reason for this question. Nodes have few bool attributes (ie. insert, update, delete permission) which would make perfect checkboxes but treeView cannot have more that one checkbox per node.
So, is there a control which could look like a treeview (nesting is only 1-3 levels deep), have extensive drag&drop functionality and support few checkboxes for each item or can treeView be modified to support this?
I suggest you take a closer look at the Telerik UI controls suite.
They offer anything you need.
Telerik UI controls
Make sure to take a look at their Treeview and TreeListView controls.
In theory, you can always try your luck with drawing the treeview yourself. Also, if it suits you, you can re-implement your own tree functionality by deriving from the listview control, and making use of the 'indentation' member of listview items. (Treeview is probably implemented on top of listview, making use of that member.)
But be prepared to have to write a lot of code and to have to do a lot of troubleshooting, because in my experience when you try to do anything out of the ordinary with these controls, they behave in a very clunky fashion.
So, if you can find a ready component somewhere which does exactly what you want, go for it. It will save you from a lot of headache.
Windows Form (in C#) - I need to create a custom listbox control for the following requirement:
There is a listbox with a long list of items. I want the user to be able to click in the list, and then start typing and have it automatically take them to the matching item (I call this "type ahead"). It needs to be able to do this for as many characters as they type that have a match.
This control should be really reusable without much changes.
What are things/points I should keep in mind while developing a reusable custom control? (if you provide a good pattern as a sample... will be more helpful)
In Real World scenario the first decision should be buy vs build. if your application is a serious one and not just for hobby and there is budget for it I would check some of those great controls collections like DevExpress or Telerik for WinForms. You would need a grid as well at some point, eventually, and surely your custom or framework one cannot compete theirs.
I refer to those libraries because i believe they already have a listbox with autocomplete as you described in your requirements. check the online demos on their websites...
Is it possible to configure the TreeView control in the Silverlight tookit such that some or all of the hierarchy levels will be automatically expanded and ideally something that can't be collapsed at that level.
I'm using this control in large part due to the ease of handling hierarchical data and the ease with which I CAN expand/collapse levels. I'm being asked to do this selectively (i.e. only at the first level should I allow expand/collapse). I'm examining a Hierarchical Data Template to try and make this happen, but am having little luck and will certainly consider other options including a different control entirely if need be. My boss DOES want me to avoid having to purchase a control if at all possible.
Thanks in advance.
Cheers,
Steve
Just an FYI for the community. I was provided and answer to this question here. The upshot is that this can be accomplished with a combination of data templates and styles.