How can I create a table like Visual Studio's watch window? - c#

I want to display data about some objects in my program, in a way similar to how Visual Studio's watch window works - A tree list with two columns, name and value, with the ability to expand non-primitive members further as child nodes in the tree structure.
I've been trying to do this with ObjectListView, but I can't seem to get it to happen. OLV seems to want to stick the members in individual columns, horizontally, while I want them to be displayed vertically, under the parent object (if that makes sense).

For winforms project there is a control - PropertyGrid that does this almost automatically, you need to set some attributes on the properties:
[ReadOnly(bool)] – is the property read only.
[Browsable(bool)] – is it browsable, i.e to show in the property grid or not.
[Category(string)] – the parent group of the property
[Description(string)] – the description. It is displayed on the bottom label when you select the property.
[DisplayName(string)] - you can override the display name.
Additional information you can find here: https://msdn.microsoft.com/en-us/library/aa302326.aspx

Related

C# WinForms - How to create a Properties Page like Visual Studio Project Properties

I'm trying to create a form that operates like the Visual Studio Properties page, with a list of categories (like Application, Build, Build Events etc) in a column on the left and corresponding information on the right. I'm planning to use either panels or a tabcontrol (with the tab header hidden) for the right hand side.
However, I'm unsure how best to create the column of categories on the left. Is there a standard control that provides this functionality?
Otherwise, I considered using a panel containing Buttons, or individual Panels, or a ListBox, but I don't think these would give the same look. Also, I don't want to write code if a suitable control already exists.
Ideally I would like to be able to easily disable all the categories, for example while editing a record on one page.
Having nested categories might be nice, but is not essential.
If the information on the right is not related to one another as you switch categories on the left, to create a good separation between categories I'd suggest you do the following:
Create a user control for each individual category
Split your form in two, the bar on the left and a panel on the right
The bar on the left, for the categories, can be a list of radio buttons, or links, or whatever you like. I'd suggest a TreeView since it easily support sub-categories.
As the user click on a category (by attaching a method to the corresponding even on the control used for the categories) you can remove the control from the panel, if any, and reset the control that corresponds to the selected category.

How do I make "TreeListControl" appear as a "TreeView"?

VS 2017
DEVEXPRES 17.2
WPF
There is a table in MS Access
Based on the table, "TreeListControl"
How to make "TreeListControl" appear as "TreeView"
I want to say how to make sure that items that are marked with crosses are not displayed
In WinForm, this is done when you set it in the menu "ViewStyle" / "TreeView"
In WPF, I did not find this.
Question.
How do I make "TreeListControl" appear as a "TreeView"?
You can accomplish your task by hiding some TreeListControl's TreeListView visual elements:
column headers (the TreeListView.ShowColumnHeaders property)
lines between cells (the TreeListView.ShowHorizontalLines and the TreeListView.ShowVerticalLines properties)
indicator panel (the TreeListView.ShowIndicator property)
And of course, you should have the only single column visible at once (the TreeListColumn.Visible property);

In a property grid is there a way to unselect all grid elements programatically?

I am working on a project in which I am using a property grid to display the properties of the selected control.
The Property Grid is fixed to the left edge of the container and in the rest of the space I have the form I am designing.
On clicking a control on the form, the specific control’s property is getting selected.
In the above figure, I have selected the textbox and the textbox’s properties get shown on the propertygrid.
Here if you observe, by default, the Name property is highlighted as well.
Is there some way to unselect this property programmatically?
I have tried some suggestions online but none have helped. I am not able to find find a way to remove all selections from the PropertyGrid, but its behaviour seem to be different form a DataGrid...
Here is why I need this...
On selecting a control, if a property in the property grid is selected, then the property is getting modified.
For example, If i cut the control using Ctrl + X, the selected value in property grid is getting cut which in some cases is forcing user to set the property before modifying anything on the form.
I have tried selecting multiple controls, but in that case alse the selected property seems to be persistent
Since PropertyGrid uses DefaultProperty to select a property in its grid, as an option you can set DefaultProperty attribute at run-time for your object to a non-browsable property, for example:
this.propertyGrid1.SelectedObject = null;
TypeDescriptor.AddAttributes(someControl,
new Attribute[] { new DefaultPropertyAttribute("Site") });
this.propertyGrid1.SelectedObject = someControl;
Well, what you are trying are hacks. It is never a good idea to do such hacks particularly if you are not the only person that use the software.
In your case, the focus should be on the designer while you interact with it. So if the user press Ctrl+X, the designer should respond to the keyboard and it should not have any effect on the property grid (as only one control can have the focus at the same time).
Thus it is up to you to make sure that your designer is focusable, that it has the focus when initially displayed, that it get the focus when you press the TAB key. Pressing the TAB key again should put the focus on the property grid so that user can interact with the grid without using the keyboard.
If you have more than these 2 controls, then obviously TAB should also stop at any appropriate controls. Also, it can be a good idea to have some direct shortcuts like F4 to (show and) activate the properties pane.
If you are not able to make it works, then the best compromise would be to use another windows for the properties grid. By using a distinct Tool windows for the properties, it should not respond to the keyboard when the main windows has the focus.
Here are some links that might help you:
Panel not getting focus
Control.Focus Method() — See Remarks section.
In any case, you should not prevent Ctrl+X to works as expected when the property grid has the focus and a property is selected. Users don't like software that do not follows UI conventions.
As a software developer, you should as much as possible ensure that your application follows standard behaviors. I recommend you that you take one or 2 extra days developing your software properly instead of doing hacks.
Often, compromise to gain a few days will never be fix and will be a pain for many years. Better to do it right from the start. Unselecting an item in the property grid is not an acceptable workaround. Your manager should not allows you to do that.

How is the Parent property of a FrameworkElement set in Silverlight?

I have written a custom Silverlight control based on Control. I have two DependencyProperties called Top and Bottom which both hold child controls for a specific layout display. I then use a ControlTemplate to arrange these two controls into a grid, placing one on the 0 row and the other on the 1 row. The problem I have is that I cannot seem to figure out how to get each child control's Parent property to point to my custom control. When I inspect each control at run-time, the Parent property of each is null.
This is a simple example, but I think you can see the general problem. I have a number of more complex controls that all share this problem. I know there is some magic I am missing. If a ContentControl's Content property is set to some child it is somehow setting that child's parent to itself.
Edit: A little more info
In WPF, one might use functions like AddVisualChild(), RemoveVisualChild(), AddLogicalChild(), RemoveLogicChild() to manage parent/child relationships, but these functions are not available in Silverlight.
After quite a bit of research I believe that this is not possible. I was able to recurse through the Visual Tree instead of the Logic Tree using the VisualTreeHelper to accomplish my ultimate goal.
The Parent property cannot be arbitrary, it reflects the real parent of the control for use when rendering.
From MSDN:
Parent may be a null reference (Nothing in Visual Basic) in cases where an element was instantiated, but is not attached to any logical tree that eventually connects to the page level root element, or the application object.
...
Changing an element's parent is typically only done through manipulation of collections, by using dedicated add or remove methods, or through setting content properties of elements.

How do I show like-values in custom fields in a property grid?

I have a property grid that helps me manage all of the controls on a form. These controls are for designer-type folks, so I'm not really worried that much about the user interface... until someone selects multiple objects.
I have a UITypeEditor for the "BottomDiameter" property on these common objects. It keeps track of units (meters vs feet) and does some nice things on-the-fly. However, when someone selects two or three common objects, BottomDiameter is blank, even though it evaluates to the same text string.
The reason (I think) that it is blank is that it is actually three separate objDiameter objects. How can I tell the property grid to behave like all of the other properties and show the value if it evaluates to the same string???
UPDATE: For example, the "Anchor" property has a text output of "Top, Right" but when you pull it down it is an object. Yet, when you select five objects on your form that all have the same Anchor setting you can still see the string "Top, Right" in the property grid.
If your BottomDiameter is a class and not a simple primitive, then you have to override the Equals method in this class.
In the TypeConvertor of the Datatype which is attributed to BottomDiameter Property, you might want to create a vistor like class called say, BottomDiameterVistor which would take an array or a list of the selected BottomDiameter(s). Override the to string property on the BottomDiameterVistor to return your aggregrated text value for the property.

Categories

Resources