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


Top 5 Contributors of the Month
david stephan
Post New Web Links

Bind ComboBox in DataGrid row

Posted By:      Posted Date: October 24, 2010    Points: 0   Category :WPF
 

Hi,

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.

Example:

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?

Thanks.




View Complete Post


More Related Resource Links

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

  
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

WPF Datagrid Combobox column

  
Hi, I am creating a WPF Datagrid with the combobox column in it. All the datagrid binding and combobox column binding works fine without any problem. But, when I select a value in the combobox column and move to the next column or row, the value is reset to the previous empty selection. Am I missing anything here? Please find the code snippet that I have used below. <dg:DataGridComboBoxColumn x:Name="technicianname" Header="Assigned To" ItemsSource="{Binding}"/> technicianname.ItemsSource = dtTechnicianInfo.DefaultView; technicianname.DisplayMemberPath = "TechnicianName"; technicianname.SelectedValuePath = "TechnicianEid"; Thanks in Advance!!! Best Regards, Subalakshmi Vijayarajan.

How to get the combobox value inside Datagrid on Edit button click event

  
Hi     I have Datagrid template column like<DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn>DataGridTemplateColumn Header="Edit" x:Name="Edit" ><DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn.CellEditingTemplate></DataGridTemplateColumn>SelectionChanged="cmbDGTeam_SelectionChanged" IsTabStop="True" /></DataTemplate><ComboBox Height="22" IsEditable="True" IsReadOnly="True" ItemsSource="{Binding}" DisplayMemberPath="Title" SelectedValuePath="TeamID" x:Name="cmbDGTeam"  SelectedValue="{Binding Path=TeamID,Mode=TwoWay}"<DataGridTemplateColumn.CellEditingTemplate><DataTemplate><DataTemplate><TextBlock Text="{Binding Title}"/></DataTemplate></DataGridTemplateColumn.CellTemplate><DataGridTemplateColumn Header="Team" Width="75"><DataGridTemplateColumn.CellTemplate> and Edit button Template column <DataGridTemplateColumn Header="Edit" x:Name="Edit" > </DataGridTemplateColumn.CellTemplate></DataTemplate><Button Content="Edit" IsEnabled="False" x:Name="btnEdit" Click="btnEdit_Click" ></Button>&l

Accessing Combobox inside WPF Datagrid Template Column

  
Hi, I am creating a WPF datagrid template column with combobox. The problem that I face now is, I am not able to bind a table to the combobox inside the WPF datagrid template column. Here is the code snippet. <dg:DataGrid x:Name="Students" AutoGenerateColumns="False" Loaded="OnLoad"> <dg:DataGrid.Columns> <dg:DataGridTextColumn Binding="{Binding Path=Name}" Header="Name" Width="75"/> <dg:DataGridTemplateColumn x:Name="Dept"> <dg:DataGridTemplateColumn.CellTemplate> <DataTemplate> <ComboBox x:Name="DeptId" ItemsSource="{Binding}" SelectionChanged="Dept_SelectionChanged" DisplayMemberPath="{Binding Path=DeptName}" SelectedValuePath="{Binding Path=DeptId}" SelectedItem="{Binding Path=Belongs}"/> </DataTemplate> </dg:DataGridTemplateColumn.CellTemplate> </dg:DataGridTemplateColumn> </dg:DataGrid.Columns> </dg:DataGrid> Please help me to find out the way to assign a dynamic source to the combobox through code behind file. Thanks in Advance!!! Best Regards, Subalakshmi Vijayarajan.

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?

DataGrid ComboBox crash

  
Maybe someone can figure out this issue. I downloaded a working example of a DataGrid Combobox and confirmed that it worked.  I basically copied the template into my application, but it's not working totally correct.  I can't find the difference in my code that is causing the problem. 1.  The values are bound correct in the combobox, but when I click twice, the drop down box appears, but the value nulls out.  In the working example, the value stays in the box.  What is causing this? 2.  When I change the value, the value selects OK.  But, when I click again (to save), I get a 'Two-Way Binding requires Path or XPath' exception.  The thing is there is no Path or XPath statement in the working example code.  What is causing this error?   Sutton  

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

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

  

Hi,

    I have datagrid control with a template combobox column like:

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

How to bind datagrid columns to external (main) datacontext?

  

Hi

I have a datagrid and his columns binds well to its collection data. But when I add a new data column (ie. DataGridTextColumn or DataGridComboBoxColumn) and Bind to the main Data Context of window the data are missing (dont show)

In this sample, The last two columns of DataGrid dont bind to the main data.

<Window x:Class="MainWindow"

 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

 xmlns:app="clr-namespace:DGComboBox.myData"

 Title

combobox in datagrid with MVVM Pattern

  

Hi

  i have requirement that, datagrid has a two column one is text column and other is combo box, combo box contain 2 column including checkbox. once i click the checkbox in combobox, resepective first column value need to display in combo box selected item and second column values need to display in first column of the data grid.

  I have used following code in xmal

 

<DataGrid x:Name="dgMixture"  VerticalAlignment="Top"  Width="250"
                      RowHeight="25"  GridLinesVisibility="Vertical" HeadersVisibility="Column" IsReadOnly="True"  AutoGenerateColumns="False"
                      HorizontalAlignment="Left" CanUserAddRows="False" ItemsSource="{Binding CompanyItemsCV}"   >
                <DataGrid.Columns>                   
       &nb

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.

 

        <!--Parameters-->
        <ListView Grid.Row="2" 
             DataContext="{Binding ScriptParameters}"
             ItemsSource="{Binding}">
          <ListView.View

I need help please : how do i bind dataGrid to dataTable Programmatically ?

  

Hi all,

 

please i need to know if i could  bind dataGrid to dataTable Programmatically using wpf V.S 2010 (without using Xaml code)???

 

i google it before but i saw solution using (DataSet) and this not useful for me because its huge application.

Note : data source is MySql.

 

Thanks a lot .

 

Abed Salem


How add and bind DataGrid columns programmatically ??

  

Hi all,

 

How are you ??

 

please i need to know how to add and bind DataGrid columns programmatically ( NOT IN XAML),

i was using  this code in windowsForms i need equivalent for it in WPF please :

            DataGridViewColumn column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "DataPropertyName";
            column.Name = "columnName";
            column.DisplayIndex = 1;
            column.Width = 150;
            column.ReadOnly = true;
            column.Visible = true;
            Datagrid1.Columns.Add(column);

 

help me please , Thanks a lot .....


 

 

 

 

 


How do I bind the ModelItem collection to combobox in XAML

  

Hi,

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}"
  DisplayMemberPath="DisplayName"  
  SelectedValuePath="DisplayName"
 />

thanks.


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:

Manufacturing

Manufacturing

Manufacturing

Automotive

Automot

Datagrid with Combobox Lookup (CollectionViewSource) -- Problem Saving Combobox Changes

  

I've developed a simple WPF application consisting of a four-column datagrid.  One of the four columns is a combobox that looks up by an id into a second table.

I can make changes to the other columns and they save just fine.  When I make a change to the combobox, it's not changed in the database.

I'm either missing something in the SelectionChanged handler or totally missing something else.

I've googled to the nth degree and haven't found any definite answers.

Any ideas?

 

Thanks,

Cindy Rae

 

The XAML:

<Window x:Class="trialWWSF2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="403" Width="525" xmlns:my="clr-namespace:trialWWSF2" Loaded="Window_Loaded">
    <Window.Resources>
        <my:WWSF x:Key="wWSF" />
        <CollectionViewSource x:Key="categoriesViewSource" Source="{Binding Path=Categories, Source={S

Categories: 
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