I have an autocomplete box where I am trying to bind the selected item to a propery of the item that is actually selected.
I.e. I have a Client object with a Name property, and the ItemsSource of my autocomplete box is a List of Clients.
The property I am trying to bind as the selected Item is a String, called SelectedClientName.
But because SelectedClientName is not of type Client, I cannot bind it directly.
As a work around, I am using a converter.
But I would like to know if there is a way to do this in the binding without converters.
I'd suggest having SelectedClientName not be of a different type, in your case of type string. Keep it the Client type and utilize your Name property where a string is required.
Here's some additional information on binding to complex objects in an AutoCompleteBox: http://www.codeproject.com/Tips/79158/AutoCompleteBox-Binding-Custom-Objects
Related
I have two property TotalWeightInGrams and TotalWeightInKiloGrams, i want to bind in label control as following output
string format="{0} ({1} Kgs)"
Easiest way would be to make a new property that returns the string you want and bind to that. This way you don't need to do anything more complicated and can change the formatting in code if needed.
I created a result view for a class, calculating some math-stuff. According to the values, set by the user, there are some of the results returning 0 or "". So some of the Controls bound to this empty properties are also empty. Thats some kind of ugly, because calculating with these Values will never contain such a result. So I don't want to show this control.
Is it possible, not to show this control if the property it is bound to is empty?
Greetings from Germany
Bind Value to element Visibility property with help of Converter that will provide your logic.
I would like to bind the text field of a textbox to an element in an instance of a structure that I've created in a class module. When I try to create a Data Source using an OBJECT type, all I see in the tree is the name of the structure, not the instance I've created. If I select the structure anyway, the Data Sources tree does show the name of the structure and the element I'm interested in. How do I bind to a specific instance? I'm using VB.net
you have to assign instance programmatically to datasource , it will not available in design time, you can do it in formload or any other event.
something like..
BindingSource.Datasource = new instance //assign to your instance to binding source
then..
TextBox1.DataBindings.Add(New System.Windows.Forms.Binding("Text", BindingSource, "Name", True))// here name propery is binding to textbox
I'm trying to obfuscate some VB.NET 2003 app.
The resulting assemblyes are obfuscated and "run" with some errors.
I cleaned all potential reflection problems, but I'm not being able to read the selected value of a combobox.
I load the Combobox using their Datasource properties, using a collection of "VTPair" (a class created by me with 2 properties: one of string type and other of object type to store the value)
This combobox handle pairs like "Male | M" or "Female | F".
When trying to see what is selected, I use if mycombo1.SelectedValue = "M" then
This code, after obfuscation, throws me an exception that cannot cast type "XX" to string "M".
So, I changed the code to something more correct, explicitly casting the selected value to String:
if ctype(mycombo1.SelectedValue,string) = "M" then
But the error is the same.
Debugin my original code, the SelectedValue property is of type "Object" but it is a string.
I tried using the ComboBox.SelectedItem property that is also an object but this time what is inside is of type "VTPair" (my own class) and then trying to access its "Value" property (which is of type Object) and trying to cast to string fails again.
Does anyone have an idea to "translate" this piece of code to work OK after Dotfucate it?
Thanks!
From MSDN:
ListControl.SelectedValue Property:
Gets or sets the value of the member property specified by the ValueMember property.
So whatever property NAME you set for the ValueMember property will be used when you use the SelectedValue property. So you may need to exclude from obfuscation, the property which you specify via the ComboBox.ValueMember property.
Not sure of the VB Syntax but in C# I think you would want something where the right-hand side is typeof(MyType). This way the type will be obfuscated to match the renamed type.
I have a gridview that is bound to a datasource on a Windows Form (VB.NET). The grid displays a list of "certifications", and each "certification" can be associated with many languages. So in the grid, I'd like to display "languages" as a column, and display a comma delimited list of the language names for each "certification".
In the "certification" class, one of the properties is a list of "language" objects, and each "language" has an ID (guid), name (string), and value (integer).
So in the datasource, I have the list of "languages", but I can't figure out how to display them in a column on the grid. The gridview won't let me add the language list property as a column.
So is the ONLY way to add a new property on the "certification" class, which returns a string that contains the comma delimited list, and show THAT on the grid? Or is there a way to display that list of "languages"?
This is not the only way, but IMHO, this is the most appropriate way. If there is some intelligent composition of data within the class (combining elements of the list into a string) that should be handled internally by the class and properties are the appropriate model. This would be similar to overriding ToString() for your object. Add to that how nicely databinding works with properties and you have a straight-forward maintainable solution.