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?
Related
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.
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!
What is the best way to remember Text/Value of a control after it is enabled again?
In my special case I have a checkbox to enable/disable a NumericSpinBox.
When checkbox is switched to Checked=false: spinbox is disabled and the last value (e.g. 10) should be remembered and the text should be cleared.
When checkbox is switched to Checked=true: spinbox is enabled again and the remembered value (e.g. 10) is reassigned.
Ok, I could store the value in an extra field of my form or container control. But if there are several controls with remembering values the additional fields are too much overhead (in terms of readability) for so small feature IMO.
So I hope you have better solutions.
You can store value in the Tag property of the numericbox or checkbox
Define a Type that represent the fields that you want and create an object of that type that hold all the state of your UI element. Set the value manually on enable or use binding
I have a a checkbox in XAML where i need the content to have a default value, lets say: "FooText", but also a binding to a field in an object, that can change.
The idea is that is that at load the checkbox should show the default content, but when an object is loaded the content should change accordingly.
Is this possible, and if so, how? I have some idea that i might be doable in a template, but since im pretty new to WPF i have no idea how to achieve the required result.
Im using the MVVM pattern.
Hope that someone might have a good idea:-D
You could use a default object for that, where you set all properties to the default value you want and then use it as DataContext.
Another thing is the TargetNullValue on Bindings. Using that you can set a default value to show if the target value of a binding is null.
It really depends on what you mean by "default value". WPF Databinding allows for a few ways to handle "default values":
FallbackValue: This allows you to specify a value if there is an issue with the databinding itself. For example, if you are binding to a property that does not exist on the viewmodel (DataContext).
TargetNullValue: This allows you to specify a value if the binding value is null, which is very possible for string values.
You can use both if you want to account for bad binding and null values, it's up to you. Either way, you should use FallbackValue often.
Create a checkboxContent property in viewmodel
set a default value to its private variable _checkboxContent = "FooText";
Bind this property to checkbox Content
When the object loads, assign the object property to checkboxContent property
I have 5 static values I would like to populate in a ListPicker control, the one that ships with the Silverlight tool-kit. I would like to be able to create these in Xaml and then reference them. I tried using ListPickerItems but the ToString() method does not return the name (which I essentially need). Is there a way of getting the x:name of these items or converting them to strings so I can get a string value back from the selected index.
These values will never change.
you could use ListPickerItems in xaml, and set each one's DataContext to the value you want. or some people use the Tag field for holding some other data too.