Array property display format in WinForms Property Grid - winforms

I have an object with a string[] property. When I assign this as the SelectedObject in the PropertyGrid, I get a "String[] Array" displayed for that property.
Is there a way I can change this display part to something else?

It sounds like it's currently displaying the ToString() value; so one option is to override the ToString() method to display a formatted string--if a string is what you want.
A little Google work turned up this post from our very own admin Mr. Marc Gravell from another place and time. His answer is pretty solid

It displays "String[] Array" because you need to provide a type converter for that property.
Here is the link with detailed solution: How to: Implement a Type Converter.

Related

can I bind a richtextbox text property to list or array in winforms

I am looking to bind a richtextbox's text property to an array or list of custom objects. Is this possible? I see lots of WPF related binding for richtextbox but I am doing this in winforms. My searches for an example article have not turned up anything of value yet. Figured I would ask here.
One of my database calls returns to me a list of specific instructions and I would like to stuff this entire list of instructions into the richtextbox all at once. The text property does not support an IEnumerable type so I am not sure if I can do what I am trying to do or not. I was looking for a method to fill my richtextbox without all the for looping and inserting one item at a time. I figured data binding was the best fit for that.
I've run across the same problem and have solved it by creating a custom ValueConverter. The code for it can be found here.
Basically it takes an IEnumerable in and then returns a string with a custom separator (defaults to NewLine).

silverlight putting item to listbox and view only some part of that object

We are working on a project with my friends and we are stuck with some point i hope you could able to help us .The problem is we are getting object from a service that we wrote and we want to put objects to listbox but in interface we would like to see only few item of that object .to make situation more clear lets say we have object a includes {name surname id} we want to put this object to list box but we would like to see only name and surname in interface .Thanks in advance .
Can ELDEM
You need to look at a Silverlight databinding example with a ListBox, such as this one: http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-5-using-the-listbox-and-databinding-to-display-list-data.aspx
Basically, you define the ListBox with the elements and styling you want and then use databinding for each of the properties you want to display: name, surname, id.
With Silverlight 5 you also can use Implicit DataTemplate that allows templates to be automatically applied to databound items based on their types.

Silverlight RadGridView change TextBox background

I am facing a small problem using silver light . I have a RadGridView, with four columns. My second columns contains text boxes and the third column contains validation errors. If the third column contains validation errors, i want the second column background to turn red. How can i do this. I have tried binding the text box background column to a string with the desired color but that does not work. Really stuck here. Any help with be much appreciated.
Regards,
Mateen
Assuming your binding is otherwise valid, you cannot change colour by binding to a text string of a colour. The background property is of type Brush.
You need to either bind to a Brush instead, or use a brush/colour converter to return a Brush instead of a Color/string etc.
Try these links for converter examples:
http://forums.silverlight.net/p/20392/70263.aspx
http://forums.silverlight.net/p/20392/70263.aspx
You need a StringToObjectConverter found here. This class has the advantage that it has wider uses that eliminate the need to create a plethora of similar converters.
Further rather than having the bound object have a property called "Background" which tell the UI to "be red". I would be better that the Model had a property called "Status" which is an enum of the possible states the object is in.
Going further and looking at your specific requirement it would be better that your model exposed a boolean IsValid property which a converter could be applied to. See this blog on a generic BoolToValueConverter.

Silverlight: binding an observable collection to different usercontrols conditionally

I'm new to Silverlight 4 and having a tough time googling this one since I'm not terribly familiar with the terminology involved. Can someone point me in the right direction?
I have an observable collection that I want to represent in an ItemsControl list. The type of the collection is a class that- for simplicity's sake- let's call PersonInfo. Each PersonInfo has a string property Name and an observable collection PhoneNumbers. Everything works fine when I tell the ItemsControl's DataTemplate to use "UserControl1" for visualizing the data- the bindings work.
My problem is that- for this theoretical example- I want to base the control used to display the PersonInfo on certain values in the Name propery. So I want to use UserControl1 for any entries named "Joe", and use UserControl2 for all others. I've found IValueConverter stuff, but that doesn't seem to help with selecting the control type used to visualize the data.
Sidenote: UserControl1 and UserControl2 show data in a similar way, but there are some differences within their complicated grid layouts that forced me to create 2 separate usercontrols. If anyone knows how I could build multiple layouts into UserControl1's xaml and then switch between them at runtime via a property binding, that would probably let me sidestep this issue altogether...
Can anyone recommend a general strategy for solving either side of this problem?
Thanks in advance!
I’ve solved a similar dilemma by using an IValueConverter in an unusual way: I created a "VisibilityConverter" that tells a control whether it ought to appear. In the case of your example you would have two of them: one Convert method would
return ((PersonInfo)o).Name == "Joe" ? Visibility.Visible : Visibility.Collapsed;
and the other would do the opposite. Then bind UserControl1's visibility to one VisibilityConverter and bind UserControl2's visibility to the other and violà, they swap out based on the data.

WPF : Nullable ComboBox

I want to have an empty item in the comboBox to allow the user to "Unselect" and keep the comboBox empty (Null value).
How can I do that?
Make your life easier by using a sentinel value. That is, an instance of your view model class that represents nothing.
If you take a look at my blog entry here, you can see a binding solution that doesn't require you to "modify" your VM or to add dummy items into a collection that doesn't really fit with your data.
Basically, you use a CompositeCollection in your XAML, which gives you the ability (for instance) to have numeric values in your combo-box, and the text "Please select..." to designate the place holder, which you can't do if you are binding entirely to numeric fields in your model and relying on that to add this magic value.

Resources