.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

How to bind to DisplayMemberPath in a customercontrol that derived from ComboBox?

Posted By:      Posted Date: August 27, 2010    Points: 0   Category :WPF
Hello, All: I need a customer control which derives from ComboBox. In its resource file I have the style:   <Style TargetType="{x:Type local:MyComboBox}">             <Setter Property="SnapsToDevicePixels" Value="True"></Setter>             <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>             <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>             <Setter Property="ScrollViewer.CanContentScroll" Value="True"/>         <Setter Property="ItemTemplate">                 <Setter.Value>                     <HierarchicalDataTemplate>                     <CheckBox Content="{Binding Path=DisplayMemberPath,Mode=TwoWay,RelativeSource={RelativeSource

View Complete Post

More Related Resource Links

How to Bind ListBox to ComboBox's SelectedItem

I have a ComboBox bound to a list of custom objects (Person). Each Person has a Friends collection. I want a ListBox below the ComboBox to contain a list of Friends depending on the Person selected in the ComboBox above it.   Something like: <ComboBox x:Name="MyComboBox" ItemsSource="{Binding People}"/> <ListBox ItemsSource="{Binding Element=MyComboBox, Path=SelectedItem.Friends}"/>   It doesn't work (null reference, I'm assuming because the SelectedItem.Friends is the wrong syntax.   Any pointers?

WPF Combobox Bind FallbackValue to Property

What I am wanting to do seems fairly simple, but WPF doesn't seem to like it. Basically I am binding a ComboBox's SelectedValue to my object:       <ComboBox SelectedValue="{Binding SendToBinLocation}" Name="cboToBin" Width="100" DisplayMemberPath="BinLocation" SelectedValuePath="BinLocation" ItemsSource="{Binding ToBinList, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" BorderBrush="{Binding Path=SendToBinLocation, Converter={StaticResource MissingBinConverter}, Mode=OneWay}"> <ComboBox.ItemTemplate> <DataTemplate> <TextBlock FontSize="16" Text="{Binding BinLocation}"/> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox>  This works fine. However, I am wanting to specify a default value for the combobox in the event ToBinLocation is empty or null. I can achieve this by hard-coding in FallBackValue=somevalue, but this is not what I want to do. What I would like to do is bind the FallBackValue to another property of the object. You can't databind to fallBackValue because it is a dependency property, so how would I go about specifying the FallBackValue with another property on the object? The idea here is that if the SendToBinLocation is null or empty, the Comboxvalu

Bind An Already Bound TextBox to ComboBox SelectedItem


Hey all,


If I have a TextBox that is already two-way bound to something, but I also want it so when a ComboBox SelectedItem changes, then the TextBox's Text property is set to the new SelectedItem.


Here's what I have so far, I added the comment where the TextBox is, which I would like to also be bound to the ComboBox below this.


        <ListView Grid.Row="2" 
             DataContext="{Binding ScriptParameters}"

How do I bind the ModelItem collection to combobox in XAML



I need to create an custom activity with a combo box that need to display all the activity name within the same parent.

Below are the code snippets that failed to list out the activities name. Anyone has any ideas to make this work?

<ComboBox Name="ActivityList" 
  ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type sas:Sequence}},Path=ModelItem.Activities}"


Bind custom list to combobox


Hi, I have a custom list which I newed to binf to a combo box, my class is as followes

Class ComboData
    Public id As String
    Public V1 As String
    Public V2 As String
End Class

I am trying the following but nothing is dispalyed in the combobox, no errors....

        Dim Listdata As New List(Of ComboData)()
        Listdata.Add(New ComboData() With {.id = "1", .V1 = "test", .V2 = "test2"})
        Listdata.Add(New ComboData() With {.id = "2", .V1 = "test2", .V2 = "test3"})
        cboSmtpServer.ItemsSource = Listdata
        cboSmtpServer.DisplayMemberPath = "V1"
        cboSmtpServer.SelectedValuePath = "id"
        cboSmtpServer.SelectedIndex = 0
        cboSmtpServer.SelectedValue = "V1"

What is missing


Thanks in advance

How to set a wpf combobox displaymemberitem to a column in 1 table and bind text displayed to a colu


I have a combobox that has a datacontext set to a 'Customer Type' that is a customer CRUD window in WPF that itself has a datacontext of 'Customer' - when i scroll through my customer table entries that have been populated into a listbox, all of the corresponding textboxes on my CRUD window update to reflect the values stored in the Customer table except the combobox.  If I change the datacontext of the combobox to be 'Customer' the text updates correctly when scrolling through but the dropdown contents are now duplicated to match the number of records.  So my problem is this;

How can I display the itemssource as the 'Customer Type.Customer_Type' datacontext, but display the Text as 'Customer.Customer_Type'?

The closest i could compare it to would be a winforms example of setting the combo's DataSource to 'Customer_Type' on the combo with a displaymember of 'Customer_Type' and then making the DataBindings 'Text' property of the combo to be 'Customer.Customer_Type' so it displays the value stored in customer but as soon as you drop it down it shows non-repeated values that are contained in customer_type.customer_type.

Right now in wpf if the datacontext is customer, the combo displays customer_type as follows:






Bind ComboBox in DataGrid row



I want to bind ComboBox to database table (via ADO.NET Entity Framework) and put it in DataGrid. Now I have DataGrid with binded TextBlock, but when I try to bind ComboBox it doesn't work.


I have table with list if countries and table users, where each user has foreign key of country where he lives.

I want to show in DataGrid user details like:

Alex Gorr     Canada     al.gorr@email.yo


And when I click on country field I want to see ComboBox with list of countries from table countries.

How can I do it?


How to bind GridView and DropDownList controls using DataTable object

In .net framework 2.0, you can load a DataTable in memory by consuming a data source using a DataReader. In this version you will find the flexibility in accessing the DataReader means write access code once and use again and again using DataReader. To see the functionality of DataTable consider an example that is created using VS2005.

How to bind TemplateField DropDownList with ArrayList?


Hi Expert!

  I'm trying gridview templateField DropDownList bind with arraylist. When i set bindsource i got this error. "//Error Object reference not set to an instance of an object."

My Sample .aspx

<asp:TemplateField HeaderText="Type">
                        <asp:DropDownList ID="_grvcboType" runat="server" Width="117px" DataTextField="Display" DataValueField="Value">
                        <asp:Label ID="Label7" runat="ser

how to bind Dropdownlist based on textbox values



I have one drodownlist which show data based om textbox values...

Let us consider i have 

Select Name from table1 where Type IN(@typ)

here @typ is textbox values

here for example textbox will have some thing like this L1,L2,L3..

How to filter Name based and shown in drodownlist based on this L1,L2,L3(on textbox)..

Help me in this

How to display related tables in one crystal report and how to link this report with combobox?


Hi! I want to display a crystal report in my vb.net application. Suppose I have tables named student details, student marks, student address, etc... Now if I want to display all these details (fields of all tables) in one crystal report (with page breaks if necessary) then how will I achieve it. I will be providing a combo box in my application that contains list of student names. How can I link this combo box with the cystal report to dynamically display report for different student on selected index change of combo box? Help me friends. An example would be appreciable.

C++ at Work: Addin a Combobox Cancel Feature


This month Paul DiLascia codes some Microsoft Office-style dialog box features.

Paul DiLascia

MSDN Magazine August 2006

.NET Reflection: Dynamically Bind Your Data Layer to Stored Procedures and SQL Commands Using .NET M


One major inconvenience of using SQL stored procedures from code is having to match type information. You have to write long wrapper functions around the procedures just to expose the data types. In the .NET Framework, however, the reflection services of the System.Reflection namespace allow you to query rich metadata that describe data types. This article explains how to use reflection in .NET to end your stored procedure nightmares. The author creates four custom classes, including one that generates a SQLCommand object based on the metadata of a method. Using this library, you'll be on your way to automating the generation of stored procedures.

Atif Aziz

MSDN Magazine August 2002

ActiveX and Visual Basic: Enhance the Display of Long Text Strings in a Combobox or Listbox


The combobox and listbox controls in Visual Basic have no built-in support for displaying text strings that are too long to fit in the visible area of either control. This article describes several techniques to improve the readability of long strings in each control. The first technique uses tooltips to display a combobox or listbox item. The other techniques, which use various Windows APIs, include adding a horizontal scrollbar for a listbox and determining the necessary width of the longest string given the font attributes of the text. The required steps are described for both comboboxes and listboxes.

John Calvert

MSDN Magazine December 2000

Change data on gridview bind


Hi there,

Simple little problem. i have a gridview that shows products assigned to a customers job. They are displayed in exVAT prices. To make it easier i want to show the inc VAT prices. How can i add VAT to 1 column in this table?

Access and Bind data wihtout using Datasource Control


i want to bind my gridview with a dataset with concept of caching (to minimize the database server trips). plz give me a best example to get and bind data to gridview (command line) . grid paging is also enabled so example code should be capable to rebind data at Gridview page change.  

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