dont show property when many object selected C# property grid - c#

I know how to prevent a property from being shown in the property grid by using this attribute
[Browsable(false)]
but I want to prevent this property from being browsed only when there are more than 1 object selected in the property grid.
I mean that when only one object is selected in the property grid this property will be shown but when 2 or more objects are selected this property won't be browsable!

Note: I haven't done it myself, but according to the documentation...
Have you tried BrowsableAttributes, documented here? In your selection code you could probably change the propertyGrid.BrowsableAttributes to reflect if it's a "solo" selection or "multiple" selection, and by tagging the variables accordingly, you should be able to have the display you're looking for.
This thread can probably help you!

Related

Unable to see the name of items in my listbox, WPF, C#

I was trying to get data from an observablecollection into my listbox, but instead of show the name of the item, I am getting Namespace.ItemClass (in my case, Retail_Items.RetailItem). I have attached an image. Where I might be wrong?
enter image description here
ListBoxItem exposes the value bound to ItemsSource by default.
And you probably bind a collection in the form of List <RetailItem>, so Namespace is printed out.
As with other people's answers, if the bound value is in the form of an object such as RetailItem, DisplayMemberPath can specify a specific property value as the output name.
This is because it dynamically creates Binding inside the ListBoxItem if DisplayMemberPath is present internally.
In fact, you can see the structure directly from the open source of the .Net Framework, which was published in Microsoft GitHub.
And I have distributed a sample source using ListBox/ListBoxItem's Style Template and MVVM structure to GITHub for you, so I hope it will help you.😀
👉 Sample Source
You should look into using a DataTemplate if you want to display multiple fields from your class or perhaps use the DisplayMemberPath property on the listbox to reference the relevant field.
Set the DisplayMember property of the listBox to "Name" (if you want the Name property to show).
e.g.-
listBox.DisplayMember = "Name";

Populate WPF C# DataGrid ComboBox ItemsSource Dynamically

I have a grid that is bound to an ObservableCollection. Basically, each item in the collection contains a different flag, that has different options. For example, ID #1 has a value that can be set to ON or OFF, and ID #2 has a value that can be set to ENGLISH or SPANISH.
So, I need to set the ComboBox ItemsSource dynamically, based on the ID (which is the first column in the grid).
What would be a good way to implement this?
Thanks!
EDIT: Some flags require a text input rather than a selection. So this would need to be implemented into the same column.
EDIT2: I was able to do this by creating a switch and returning the specific list based on the ID, and setting it as the ItemSource Binding.
I was able to do this by creating a switch and returning the specific list based on the ID, and setting it as the ItemSource Binding.

Multiple combo boxes bound to same source with conditional visibility on items

Unlike many questions related to this, I'm not having an issue with all combo box values being changed at when changing one combo box selection.
My problem is that I want to change the visibility of certain items when they are selected in the other list. I have two input port combo boxes and when I select port 5, say, on the first one, I want port 5 to not appear in the drop down for the second combo box.
I've tried this solution How to set combox item visibility? as it looked very promising but it won't let me cast from string to ComboBoxItem in the code-behind.
What else am I to do? I thought of creating a style in the XAML itself, but I can't quite figure out the conditions to use within the XAML and can't seem to find any topics over it. Lastly, I also have conditions in the setters for my input properties to check that the value the port is being set to is not the same as the other port, but it's not seeming to do anything for the view.
Are you using an ObservableCollection? This would allow for two way data binding whereas your UI will reflect the contents of each ObservableCollection in realtime if added to or removed from in an event. In another scenario, I had to apply a custom object to bind to in order to determine whether or not to show it, however, it was not the contents of a combobox, which are harder to access.

Check validation errors for all bindings bound to current DataContext

I have a form with some controls (say TextBox) which Text property is bound to some DataContext (say DataRowView).
I want to know if this row was filled correctly without any validation errors. I have found one possible solution. But I do not like it. It is not good to enum all the DependencyObjects on a form. Is there any way to enum only those DependencyObjects which was bound to this DataContext? May be some magic with BindingOperations...
How do you validate the input-data?
Maybe you could use a BindingGroup and then check it's Validation.HasError attached property.

C# How to set default value of a string collection in Design

In WinForm, I have a combobox with DropDownStyle set to DropDownList (so can't enter a Text). In the properties window, there is the Items property which is a string collection. I enter all my values.
But now, I would like to set one of these value by default (instead to have the empty entry at run-time). I know how to do this via coding, but I am pretty sure (damn memory) that it was possible to set one of the value in the string collection as default by adding a special symbole in front of the line.
Anybody know that symbole? Or my memory is playing me trick and it is not possible to do it via the designer?
Doesn't look like it can be done when using a DropDownList. From here it is suggested that you can set the text property to the default value you want, but this will only works in a DropDown rather than DropDownList style.
I'm sorry but that is not possible within the Designer only, since the Text property is used for this feature and that property is ignored/cleared when the using a DropDownList.
If you don't mind having your data values outside of the Designer, you could probably use DataBinding to accomplish this since the DisplayMember and ValueMember properties of ComboBox can be used in the Designer and would set the display value. I don't normally use DataBinding so unfortunately I cannot provide code examples - perhaps another user can chime in?

Categories