.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

Binding combo box to List box

Posted By:      Posted Date: September 07, 2010    Points: 0   Category :WPF
Hi,      I am fairly new to WPF and i am trying to bind two controls on a page.  What i have is a combo box with one datacontext and a listbox with another.  What I am trying to do is when you select an item in the combobox it will filter the listbox by that selected item.  Below is the xaml for the listbox and the combo box.  the data is the combo box is a code and description.  The code in the list is a key ( the code) and a list of items for that code. Thanks in advance Art <   ComboBox Margin="0.027,23,80.682,0" Name="cboTraitParam"   ToolTip="Select a security Trait to specify for your autobid filter"   Height="22.168" VerticalAlignment="Top" Grid.ColumnSpan="5"   IsSynchronizedWithCurrentItem="True"   ItemsSource="{Binding}"   ItemTemplate="{StaticResource Muni_dropList}"   Grid.Column="1" /> <   ListBox   Name="ParamList" MinWidth="169" SelectionMode="Multiple"   IsSynchronizedWithCurrentItem="True"   ItemsSource="{Binding ElementName=cboTraitParam,   Converter={StaticResource SecurityParamConverter},   Path=SelectedValue }"     Margin="6,111,0,

View Complete Post

More Related Resource Links

Binding multiple combo boxes to the same list


If I bind multiple combo boxes to a list of combo box items, selecting an item in one box clears the list in the other. When I use a list that contains something other than combo box items the binding works as expected. Is this a bug or am I missing something?

Here is an example of the behavior using VS 2010 premium and .Net 4.0

<Window x:Class="TestApp.MainWindow"

Binding an array to dropdown list


I have the following string which is a list of urls. How do I get this to work so the url shows for the selection and also is the value?      


allLinks = newAllLinks
        Me.DropDownList1.DataTextField = "Link"
        Me.DropDownList1.DataValueField = "LinkURL"
        Me.DropDownList1.Items.Insert(0, New ListItem(" - Select - ", 0))
        Me.DropDownList1.DataSource = allLinks


 ArgumentNullException: Value cannot be null.
Parameter name: container]
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +121
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName, String format) +8

Binding to child list

I have a wpf datagrid that is bound to my business object, Caregivers, which is a custom list of Caregiver.  The Caregiver object contains a child list, ScheduleList, which is a custom list of Schedule. I have successfully bound the datagrid to the Caregivers object using a collectionviewsource and setting the source to my custom object.  I now want to bind the datagrids row details to the child list but I am having trouble.  Here is what I'm trying: My Datagrid is:      <DataGrid Name="DataGridSummary" ItemsSource="{Binding}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" > <DataGridTextColumn Header="Name" Binding="{Binding Name}"/> <DataGrid.RowDetailsTemplate> <DataTemplate> <Border Margin="5" Padding="2" BorderBrush="DimGray" BorderThickness="0" CornerRadius="3"> <DataGrid Name="DataGridDetails" ItemsSource="{Binding ScheduleList}" HorizontalGridLinesBrush="LightGray" VerticalGridLinesBrush="LightGray" AutoGenerateColumns="True" CanUserAddRows="False" CanUserDeleteRows="False"> <!--<DataGridTextColumn Header="Clie

text box binding with Generic list

Hi, I am working in asp.net 3.5 page, where I want to bind a textbox with generic list data. And I have Previous & next button. Which will show the record in textbox. I don't want to go in db again and again.  Is it possible.??? 

Data Binding a DataGrid to a list fetch the same data multiple times

Hi, I'm using DataGrid to show data through data binding. My data are provided in a list. The setup I have is the following: DataGrid "binded" to the default view of my list that implement IList<T> and IList interfaces (MyList<T> : IList<T>, IList, INotifyCollectionChanged)             CollectionViewSource.GetDefaultView(_myList);             // Set the data context             DataContext = view; T: is here my 'business object' that hold the data, called 'MyRow'. Then the columns of the DataGrid are bound to public properties of 'MyRow' object. MyRow class has a public property of type 'object' (public object data[int index]) and first column of datagrid is bound to myRow.data[0], second column is bound to myRow.data[1] and so on.   When the datagrid is displayed, databinding kick in and my data are showed in the control. The issue I'm having is that data fetching is very repetitive even for the same rows. For example for a datagrid with 20 visible rows, the first row is fetched multiple times even if the datagrid is not resized or moved. I put break point inside my list (MyList<T> into This[T] property (public T this[int index]) and i got multiple hits into the property for the same index. Fetc

Problem with Binding Dictionary to Combo Box Control

Hi All,I am trying to figure out how to bind <Key,Value> pair to Combo Box Control in WPF. By now i have found that the following code do not hold Keys in the comboBox:[vb Code]Dim MyDictionary as Dictionary(OF String,String)MyDictionary.Add("Key1","Value1")MyDictionary.Add("Key2","Value2") ..etc.'***** MyComboBox is ComboBox control ******MyComboBox.ItemSource =  MyDictionary.Values[xmal]<xmls:ComboBox x:Name="MyComboBox" />Doing the above process does not fulfill my purpose of capturing keys. Example if i want to get the "Key" for "selectedItem" then i cannot since i have not binded it.Can anyone suggest me a solution? If anyone can provide me with a xmal and code behind that would be great!!!THanks in Advance.

Binding list to form not working with '&' character in list field data

Hi, I have a SharePoint list with a field called Title. I have a form based on this list with the field bound to the form as a label (for workflow to access). Here is the code for the form field. <asp:Label runat="server" id="ff2{$Pos}" text="{@Title}" __designer:bind="{ddwrt:DataBind('u',concat('ff2',$Pos),'Text','','ID',ddwrt:EscapeDelims(string(@ID)),'@Title')}" /> I have a workflow that runs through a form action button which take ff2 (title) and  does other stuff. The problem I have is with records where the value of 'title' contains the '&' character (example ab&cd). Blank is pulled in by the workflow when I get the value of ff2. I am guessing it has to do with the data binding and/or escape (special) characters coming through but I don't know how to fix it. Any help will be greatly appreciated

Drop down list not data binding




I am trying to data bind a drop down list inside a formview but for some reason when I click the update button I get the follwoing error message:

'ddl_activity_status' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: 'ddl_activity_status' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentOutOfRangeException: 'ddl_activity_status' has a SelectedValue which is inval

Drop down list Not Binding on Visible false


Hello i have a textbox1 and drop down list 1

i am filling drop downlist from Sql datasource

and  textbox1.text=Dropdownlist1.SelectedItem.Value.ToString()

all working fine

but if i set dropdownlist1.visible = false  than  textbox1.text = empty string

I need to hide the dropdownlist1 and in the same time i need the selecteditem of dropdownlist   to be in the Textbox1.text

please help me

Problem in binding List<> object to Gridview



We I bind a list<> object to a gridview it calls an error like this:

Error: DataBinding: 'Default2+JobsList' does not contain a property with the name 'JobId'

Hear is my markup Codes:

<asp:GridView ID="GridView1" runat="server" DataKeyNames="JobId" AutoGenerateColumns="False"
                                <asp:BoundField DataField="JobName" .../>
                                <asp:BoundField DataField="JobExplain" .../>
                                <asp:ButtonField CommandName="DeleteJob" .../>

and Code behind:

public struct JobsList
        public int JobId;
        public string JobName, JobExplain;
        public JobsList(int id, string name, string explain)
            JobId = id;
            JobName = name;
            JobExplain = explain;

List<JobsList> list = new List<JobsList>();


list.Add(new JobsList(Approperiate Attributes..));
GridView1.DataSource = list;

Binding GridView to a List and setting HyperlinkField


Hello all. I am new to using Data Controls and would appreciate your help. I have a List<string> that I want to use as a datasource for the gridview, making the column a HyperlinkField type and passing the value clicked in the column in the url. My code:

private void DoBind(GridView grid, List<string> Accounts)


Hyperlinkfield field = new HyperlinkField();

field.DataNavigateUrlFields = Accounts.ToArray();

field.DataNavigateUrlFormatString = _urlToRedirectFromGrid;

field.DataSource = Accounts;


grid.AutoGenerateColumns = false;



I can't get this to work. The page throws an AJAX null exception when this method is called.

shared item list for combo box's


Language :C#.

I have 'n' combobox controls on a form, each of the combobox's use's a shared list of items and if an item appears in one combobox, I don't want it to appear in the list for the other combobox's, of course if the user selects a new item the od item has to be made available again.



list { 1, 2, 3, 4, 5, 6}

combobox1 selects 3 (if no items are selected then al are available)

combobox 2 can select {1, 2, 4, 5, 6} selects 5

combobox 3 can select{1, 2, 4, 6}

I had thought to use a class as in examble 2

public class regionlist
    private string Name;
    private bool Flag;

    public string name
        return Name;
        Name = value;
    public bool flag

Binding Text contains "comma separated items" to a checked list box


Stundent record contains a text field, this field contains a comma separated courses that the student have.
I designed a WPF form showing that field and alos a cheched list box showing all available with some items checked according to that text field. here is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MicrosoftCourses
  /// <summary>
  /// Interaction logic for MainWindow.xaml

SharePoint User tracking and PeoplePicker binding to SharePoint 2010 List



First, apologies as I'm not sure if this is best forum for these questions. I'm pretty new to both SharePoint and Infopath, but am now having to learn both ASAP.
The enviroment is Windows Server 2008 Standard SP2, SharePoint 2010 Foundation, SharePoint Designer 2010, InfoPath 2010 (but targeting InfoPath 2007 client as this is what is rolled out in the company) and VS 2010.

My first question has to do with how the PeoplePicker control interacts with a User field (Person or Group column) in a SharePoint 2010 list; I don't quite get how to bind the control to the field (which I move into MainDataSource after retrieving the list item in XML via OWSSVR web service). If I create the 2 groups and 3 fields manually (or programtically) in the MainDataSource, how do I populate them from the XML data and which are the bits that need to be written back when I update?

Next question: what is the easiest way to lookup extended information about a named user, e.g., to make sure that the person being selected for a field is a member of group ZYXXY. Remember I'm using InfoPath 2007 client.

My last question is a bit more general with respect to how/where SharePoint caches User information. The company keeps AD updated for current employees and other users, but obviously there is turnover and policy is to remove them. What happens to list ite

Binding an event handler to a list



I am trying to bind an event handler to a list using the following code. I have the same code before with success, but I am not sure why it is not binding it anymore. Also I am getting no error, but the event is not firing when I bind the event handler using the following code:


static void Main(string[] args)
      int check = 1;
        SPSite collection = new SPSite("https://fullsitepathhere");
        Console.WriteLine("Working - 1");
        check = 3;
        SPWeb site = collection.OpenWeb();
        Console.WriteLine("Working - 2");
        check = 4;
        SPList temp = site.Lists["Data Storage"];
        Console.WriteLine("Working - 3");
        check = 2;

        string assname = "NewSaas, Version=, Culture=neutr

combo box custom template and binding issues


i have a custom styled combo box binding with an enum, issue is that when i select the item from the combo box the interface dnt get refereshed and evern after selection the dropdown list remains there. and if i remove the style it works fine.. 

below is the custom style i am using. can you please let me know 




    <Style TargetType="ComboBoxItem">

        <Setter Property="Background" Value="Transparent" />

        <Setter Property="HorizontalContentAlignment" Value="Left" />

        <Setter Property="Padding" Value="6,4" />

        <Setter Property="KeyboardNavigation.ControlTabNavigation" Value="Local" />

        <Setter Property="VerticalContentAlignment" Value="Top" />

        <Setter Property="Template">



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