I came to know the same thing for string using the link How to Populate a List<string> in XAML?
But need to do the same on object (say for string only)..
Use the binding context to populate the list. Set the binding target as list object and binding source as the source of data.
Look here for example. I think it answers your question.
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 need to write a custom collection where it will store the selectedindices of the datagridview. Sine we have SelectedRows colllection property already present in Datagridview. I want to use it and get indices collection so that I can I can create SelectedIndices as a custom property for my Datagridview which is of type collection. Can some one help m eon how will I do it.
For reference;
Selectedindices is a property of Listview provided by microsoft.I want the same with Datagridview. But since I don have that I want to use the SelectedRows property and an create a custom property Selectedindices for my datagridview. It should be of type Collection. PLease suggest if I can do the same .
I do believe that feature is already available, maybe you can find out more by view the link below?
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewselectedrowcollection.aspx
Also a little code sample of how far you got, or what you have tried already always entices other members to be more helpful.
I am trying to show xml data in an Ultragrid. I have tried using Ultragrid.loadfromxml and using the location of the file and i have also used a file input stream and throw that into the load xml method. any help?
For this purpose you can load an XML file with something like this
Dim dt as DataTable = new DataTable("myData")
dt.ReadXml("path_to_your_file")
ultraGrid1.DataSource = dt
The UltraGrid can bind to anything that implements IList so you will need to load the data into a list of some kind. If you need the grid to respond to changes to the collection after the initial load of the data then you would want to use an IBindingList. There are more details on what the DataSource can be set to in the online help:
http://help.infragistics.com/NetAdvantage/WinForms/Current/CLR2.0/?page=Infragistics2.Win.UltraWinGrid.v12.1~Infragistics.Win.UltraWinGrid.UltraGridBase~DataSource.html
If you XML is in a format that can be read into a DataTable then the simplest solution is to bind the UltraGrid to a DataTable after calling ReadXml to load the data into the DataTable.
If you aren't able to use a DataTable, then you could use LINQ to XML to get the data and convert it to something that the UltraGrid can bind to.
To quote the Infragistics Ultragrid Ninja, Mike Saltzman, himself:
The grid needs some sort of data source that implements either IList or IBindingList. So you would have to load your XML into an object of one of those types.
So you'll need to load your XML into some collection type that implements one of those interfaces and then set that as the data source on the grid. Take a look at this question for how to load XML from a file. Then it's as simple as ...
UltraGrid1.DataSource = myAwesomeBindingListMadeFromXML
The LoadFromXML method on the UltraGrid.DisplayLayout that it designed for loaded a previously saved off layout (i.e. display settings), not the data in the grid itself.
I need to add a panorama item in a selected index like remove ,instead of adding in the last by default.Is it possible to do that
That is perfectly feasible.
First give your panorama control an explicit name (for example x:Name="MyPanorama")
Then use code similar to the following to insert a panorama item at a specific index:
MyPanorama.Items.Insert(0, new PanoramaItem() {Header = "Panoramo 0"});
Hope this helps!
There are two ways of doing this as PanoramaItems can either be set directly or bound through an ItemsSource.
The Panorama Items property is just an ItemsCollection and so support Add(), Clear(), Insert() and Remove() methods which should cover all the scenarios you mention in your question.
Alternatively, if you specify an ItemsSource which is populated with an Enumerable which also implements INotifyPropertyChanged then you could just update the source directly.
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