.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Help binding ComboBox to XML file using c#

Posted By:      Posted Date: September 27, 2010    Points: 0   Category :WPF

I have a ComboBox defined as such (fragment)

<ComboBox Margin="4,0,1,3" Name="ComboBoxGroupSelector" SelectedValuePath="URL" ItemsSource="{Binding}"


and in my code-behind I am trying to bind it this way:


public static XmlDataProvider calendargroupdata = new XmlDataProvider();

                calendargroupdata.Source = new Uri(@newBindingPath, UriKind.RelativeOrAbsolute);
                calendargroupdata.XPath = "/Groups/Group";
                System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
                binding.Source = calendargroupdata;
                binding.XPath = "Description";
                ComboBoxGroupSelector.SetBinding(ItemsControl.ItemsSourceProperty, binding);


Xml file format is like this:

<?xml version="1.0"

View Complete Post

More Related Resource Links

Binding value to combobox or dropdown


How can we bind a value to a combobox or dropdown? What is the property for binding a value? 


TextBox shows binding source text when window load, so why not with the ComboBox?

How can I get a ComboBox to show the binding source value when my window opens?  I have been searching all day for a solution to this, but cannot find anything.  So I have created a sample project to demonstrate my problem.  Below is a Vehicle class, very simple, two members Category and Make.  Category is an enumeration, Make is a string. namespace ComboExample { public class Vehicle { // Constants and enumerations public enum eCategory { Road, Air, Sea } // Attributes public eCategory Category { get; set; } public String Make { get; set; } // Construction public Vehicle(eCategory Category, String strMake) { this.Category = Category; this.Make = strMake; } } } Here is the C# for the MainWindow.  A new Vehicle object is created as a member.  In the constructor I set a data-provider in the XAML to this Vehicle object.  There is a button event for showing the values of the controls and objects so I can check the binding. namespace ComboExample { // Interaction logic for MainWindow.xaml public partial class MainWindow : Window { // Attributes Vehicle m_Car = new Vehicle(Vehicle.eCategory.Road, "BMW"); // Construction public MainWindow() { InitializeComponent(); // link data-p

How to set and map a Method in the Service file with endpoint elements and binding elements

Hi all, I have created a service file like OSService.svc in that i have two methods like one is FileUpload and FileDownload for e.g :- [WebInvoke(UriTemplate = "/fileupload/{fileName}" , Method = "POST" )]         [OperationContract]         void FileUpload(string fileName, Stream fileContents); same as Filedownload also. People you may know these methods are inside the interface of service file what you are using i'e i have created a interface as IOSService.cs. So, what i need now is i want to write separate endpoint for FileUpload and Filedownload.Because i want to set separate value for receiveTimeout  and openTimeout for the Fileupload and FileDownload process in binding section in the web.config file itself. The below code was i'm using right now but still i'm not able to the set separate value of endpoint elements in the bindings. EndPoint Section:- <endpoint name = "endPoint1"  address  = "localhost:8000/OSService.svc/" bindingConfiguration = "TransactionalTCP"   binding  = "netTcpBinding"          contract = "IOSService"/> Binding Section:-  <binding name = "TransactionalTCP"  transactionFlow = "true"   /&

ajax combobox having problem in binding data

Hi i am using ajaxtoolkit:combobox and i tried to bind data to this control in code behind file. but it is taking 3 to 4 mints to bind data and display the page. what is the problem? I am providing my aspx code and code behind code here<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="TestPage.aspx.cs" Inherits="Dashboards_TestPage" Title="Untitled Page" %> <asp:Content ID="Content1" ContentPlaceHolderID="cphMain" Runat="Server"> <asp:ScriptManager runat="server" ID="scriptMgr"> </asp:ScriptManager> <table border="1"> <tr> <td> <ajaxToolkit:ComboBox ID="ddlProgram" runat="server" DropDownStyle="DropDownList" AutoCompleteMode="SuggestAppend" CaseSensitive="False" MaxLength="10"> </ajaxToolkit:ComboBox> </td> </tr> </table> </asp:Content>  Code behind code:public partial class Programs_TestPage : System.Web.UI.Page { ProgramData programData = new ProgramData(); protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack)

Element Binding - ComboBox

  <ComboBox Height="23" HorizontalAlignment="Left" Margin="139,59,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120" > <ComboBoxItem Content="Spain"/> <ComboBoxItem Content="England"/> </ComboBox> <ComboBox Height="23" HorizontalAlignment="Left" Margin="139,154,0,0" Name="comboBox2" VerticalAlignment="Top" Width="120" > <ComboBoxItem Content="Madrid"/> <ComboBoxItem Content="Barcelona"/> <ComboBoxItem Content="London"/> <ComboBoxItem Content="Birmingem"/> </ComboBox> I've problem... I want to use element binding, in this source to filter Cities by selected Countries how do it?  

Binding to a custom App.Config file in dotnet 4.0

Hi, I need to resolve Mixed Mode assembly issue using below text in configuration file. <?xml version="1.0"?> <configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> </startup> </configuration> But, it seems to be work only in APP.CONFIG file. and does not work in custom configurationfile (custom.config).   I gone through the below article: http://weblogs.asp.net/israelio/archive/2005/01/10/349825.aspx still it does not work seems to be work for resolve Mixed mode assemly issue. Please let me know if any one has idea on this.   Thanks, Dhaval Soni    

Binding ListBox to ComboBox's SelectedItem

Hi All,   I have a ComboBox that is bound to a collection of People. When the user selects a Person in the ComboBox, I want a ListBox below that to be populated wtih the Person's Friends.   Is it something like:   <ComboBox x:Name="PeopleComboBox" ItemsSource="{Binding People}"/> <ListBox ItemsSource="{Binding ElementName=PeopleComboBox, Path=SelectedItem.Friends}"/>   I'm going for something like that.

Problem whit ComboBox binding in WPF

Here are my main classes: Configuration { List<Environment > EnvironList, Source ConfigSource } Source { List<FileSource > FileSourceList } FileSource {} inherits class     SourceInfo { string Id, string Source } Environment { List<FileDestination > EnvirFileList } FileDestination { List<String> DestinationList } and inherits class     Info { string SourceId } Info .SourceId refers to SourceInfo .Id. Example: Id="mySource" Source="C:\PathToMyFiles" The Configuration is read from an XML file. In my display, I want to gatter all the SourceInfo objects of my Configuration and put them in a comboBox, to be available for selection in the Environment ->FileDestination ->Info .SourceId. So far, no problem. I also want to select the current value. I did that by putting it at the begining of the list and selecting that index when the list is created. The problem I have is when I try to modify the value. When I change the selection, it shows me the new value, but that value is never saved. If I reload the list, the old value is selected. Also, when I add a new File in the  Environment .EnvirFileList, the SourceId is never added to the XML file. That XML file is create with Serialized properties from my classes. If I remove the ComboBox and use a textbox, the value is added to the XML file. Below is

Adding new rows to Datagrid with a Combobox column generate "two-way binding requires path or xpath"



    I have datagrid control with a template combobox column like:

 <DataGridTemplateColumn Header="Fault code" Width="75">
                                    <TextBlock Text="{Binding FaultCode1}" />

autocomplete combobox/textbox binding to dataset


Hi All.

I found sample http://www.codeproject.com/KB/WPF/WPFAutoCompleteTextbox.aspxAutoComplete ComboBox where data is hardcoded in the code. I would like to use AutoComplete ComboBox binded to dataset. I don't have a problem binding data to ComboBox but I have problem if need that combobox autocomplete and filtered listbox. That is bit of code which I found

  Public Sub New()

    textBox1.AddItem(New AutoCompleteEntry("Toyota Camry", "Toyota Camry", "camry", "car", "sedan"))
    textBox1.AddItem(New AutoCompleteEntry("Toyota Corolla", "Toyota Corolla", 

combobox selected item value doesnot get updated when binding value changes


i have a combobox  as below






<ComboBox TextSearch.TextPath="Label"

WPF ComboBox Binding problem



I have combobox that is has its itemsource bound to a list returned from DB, as follows




ComboBox Name

ComboBox : Display selected value with Binding



I have a problem with my ComboBox, it won't show the selected value even if it select it. Items are binded.

Code behind: Me.DataContext = from Miss in myXDoc.<Miss>

Code XAML :





Binding a Collection to a ComboBox


The following is a the class, a list of which I wish to display in a WPF combo box
    public class DivisionItem

        private int _divn_ID = -1;
        private string _divn_Nm = "";
        private int _divn_Mgr = -1;

        private string _addrLn1 =&nb

ComboBox not querying SelectedValuePath when binding initial value


Hi everyone,

I came across this weird problem with a combo box (also tried list box) where its initial value is not set to the requested value based on the property named in SelectedValuePath. In some cases, the combo box is empty initially but it populated its available items correctly, and I can later set the values, etc. Everything works except the initial value.

Here is my combo box declaration:

<ComboBox ItemsSource="{Binding States}" DisplayMemberPath="Function" SelectedValuePath="Value"
     SelectedValue="{Binding Value, Mode=TwoWay, ValidatesOnExceptions=True}"
     MaxWidth="150" Width="150" Grid.Column="1" />

By itself this works perfect. The problem comes when this is combined with another combo box in a different part of the interface which displays items based on the same collection.

The above combo box declaration is used in a popup window that is activated by a toggle button from a tree view item. But I also have a combo box displaying the same set of values in a property grid (although that combo box is populated slightly different due to property grid requirements).

The combo box in the property grid works perfect in every scenario (there is always an initial value). The combo box in the tree view item popup does not show

WPF Combobox SelectionChanged with record binding


In my xaml, I have a ListBox of Customers on the left. When a customer is selected, the right will display the customer info (name, address, phone, type, etc) to a bind textbox or combobox.

On the right, the Type is a combobox that has SelectionChanged event that populate something when value is changed. The problem is whenever I select a different customer in the ListBox on the left, the Type SelectionChanged event also fire up and populate value. How can I detect and prevent this from happening? thanks!

Combobox inside Listbox binding issue

I am lost...

I have the following two classes (simplified)

Class Parent
    String Description{get;set;} 
    ObservableCollection<Children> ListOfChildren = new ObservableCollection<Children>();

Class Children
    public string Name{get;set;}

And the following two lists :

public List<Parent> ListOfParents = new List<Parent>();
public static List<Children> StaticListOfChildren=new List<Children>();

Now I have a list in XAML, I set the datacontext of this list to the "ListOfParents" (in code) and set the ItemSource="{Binding}"
All works fine so far. Inside this list I have another list containing the "ListOfChildren" list. The itemtemplate of this list contains a combobox. This combobox binds to the "StaticListOfChildren" list. The problem is now I can't get the selecteditem of the combobox to bind to the Children item in the ListOfChildren.... Can anyone help ??

<ListBox x:Name="lbMaterialsBuildup" HorizontalContentAlignment="Stretch" ItemsSource="{Binding}">
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend