Welcome to the Xceed Community Sign in | Join | Help
Community Search  

How to bind a DataTable to a ComboBox in WPF DataGrid?

Page 1 of 2 (17 items)   1 2 Next >
Sort Posts: Previous Next
  •  05-05-2008, 8:07 AM Post no. 11960

    How to bind a DataTable to a ComboBox in WPF DataGrid?

    Hi,

    How to bind a DataTable in the same code-behind to the ComboBox column of the DataGrid?

     

    Thanks,

    Venkatesh Mookkan 


    Venkatesh Mookkan
  •  05-05-2008, 9:31 AM Post no. 11965 in reply to 11960

    Re: How to bind a DataTable to a ComboBox in WPF DataGrid?

    The Solid Foundation sample will provide you with all the code and examples to set up what you are trying to do.

    You can also refer to this thread:

    http://xceed.com/CS/forums/thread/11810.aspx



    Marc Laroche
    Software Developer
    Xceed Software Inc.


    I don’t suffer from insanity, I enjoy every minute of it. - Unknown
    Filed under:
  •  05-05-2008, 11:06 PM Post no. 12000 in reply to 11965

    Re: How to bind a DataTable to a ComboBox in WPF DataGrid?

    Hi Marcus,

    I tried the example given over there. But it failed. I have pasted the XAML of my Grid control.

     

                        <xceed:DataGridControl Margin="10" Height="350" Name="MappingGrid" Width="Auto" VerticalAlignment="Top" CellEditorDisplayConditions="MouseOverCell" ValidationMode="CellEndingEdit">                                                                  
                                <xceed:DataGridControl.View>
                                    <xceed:TableView />                                                                       
                                </xceed:DataGridControl.View>
                                <xceed:DataGridControl.Columns>
                                    <xceed:Column FieldName="sequence" Title="Sequence" ReadOnly="True" Width="60" />
                                    <xceed:Column FieldName="sample_data" Title="Sample data" ReadOnly="True" Width="150" />
                                    <xceed:Column FieldName="field_name" Title="Source Field Name" Width="150">
                                        <xceed:Column.CellValidationRules>
                                            <validation:SourceFieldValidationRule />
                                        </xceed:Column.CellValidationRules>
                                    </xceed:Column>
                                    <xceed:Column FieldName="target_info" Title="Target Field" CellContentTemplate="{StaticResource MappingStyle}" CellEditor="{StaticResource MappingEditStyle}" Width="200" />
                                    <xceed:Column FieldName="target_db" Title="Target DB" Visible="False" />
                                    <xceed:Column FieldName="target_table" Title="Target Table" Visible="False" />
                                    <xceed:Column FieldName="target_column" Title="Target Field" Visible="False" />
                                </xceed:DataGridControl.Columns>
                            </xceed:DataGridControl>

     

    I have a DataTable in the same code behind say "SourceFieldsTable". I want to bind that to the Column with FieldName = "field_name". I created a CellEditor with a ComboBox and Binded the DataTable. Its showing empty ComboBox only.


    Venkatesh Mookkan
  •  05-06-2008, 8:34 AM Post no. 12010 in reply to 12000

    Re: How to bind a DataTable to a ComboBox in WPF DataGrid?

    Do you have any binding errors in the output window?
    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  05-07-2008, 5:31 AM Post no. 12037 in reply to 12010

    Re: How to bind a DataTable to a ComboBox in WPF DataGrid?

    No Jenny.

    Venkatesh Mookkan
  •  05-07-2008, 8:34 AM Post no. 12038 in reply to 12037

    Re: How to bind a DataTable to a ComboBox in WPF DataGrid?

    Can you provide more details, such as the XAML for the MappingEditStyle?


    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  05-08-2008, 10:42 PM Post no. 12117 in reply to 12038

    Re: How to bind a DataTable to a ComboBox in WPF DataGrid?

    Hi Jenny,

    See the below which is the CellEditor I used before for the ComboBox which is not working.

    <xceed:CellEditor x:Key="SourceFieldEditStyle">
                <xceed:CellEditor.EditTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" AllowDrop="True">
                            <ComboBox ItemsSource="{Binding dataMapFields}" DisplayMemberPath="field_name" SelectedValuePath="field_name" HorizontalAlignment="Stretch"/>
                    </StackPanel>
                    </DataTemplate>
                </xceed:CellEditor.EditTemplate>
            </xceed:CellEditor>

     

    This CellEditor is used for the Column with FieldName "field_name". Here "dataMapFields" is the DataTable in the codebehind. I hope this details would help to debug my problem.

     
    If possible give me a sample code that will load DataTable to a ComboBox in a DataGridControl. The filling up of the DataTable should be dynamic and code should not be in App Context.

     

    Thanks
     


    Venkatesh Mookkan
  •  05-09-2008, 3:14 PM Post no. 12134 in reply to 12117

    Re: How to bind a DataTable to a ComboBox in WPF DataGrid?

    You also need to bind the SelectedValue of the ComboBox using a CellEditorBinding. You can refer to this post for an example.

    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  05-12-2008, 4:37 AM Post no. 12158 in reply to 12134

    Re: How to bind a DataTable to a ComboBox in WPF DataGrid?

    Hey Jenny,

    I tried with the post you mentioned. But it is not working. The ComboBox is show empty still. I changed my CellEditor resource as,

     
            <xceed:CellEditor x:Key="SourceFieldEditStyle">
                <xceed:CellEditor.EditTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" AllowDrop="True">
                            <ComboBox ItemsSource="{Binding dataMapFields}" SelectedValue="{xceed:CellEditorBinding}"  DisplayMemberPath="field_name" SelectedValuePath="field_name" HorizontalAlignment="Stretch"/>
                    </StackPanel>
                    </DataTemplate>
                </xceed:CellEditor.EditTemplate>
            </xceed:CellEditor>

    Thanks


    Venkatesh Mookkan
    Filed under: ,
  •  05-13-2008, 10:47 PM Post no. 12232 in reply to 12158

    Re: How to bind a DataTable to a ComboBox in WPF DataGrid?

    Does this problem resolvable?

    Venkatesh Mookkan
  •  05-14-2008, 8:30 AM Post no. 12243 in reply to 12232

    Re: How to bind a DataTable to a ComboBox in WPF DataGrid?

    Hi Venkatesh,

       I've looked through your code and I've been wondering: Is there a "dataMapFields" property on the objects mapped to the cell for the Column?

       I do ask because I notice that the binding to load the ComboBox ItemsSource refers to a Binding to a "dataMapFields" on the DataContext.

       <ComboBox ItemsSource="{Binding dataMapFields}"

       If there is no "dataMapFields" property on the Cell`s Content, then it is normal that you are not seeing anything in the combo box.

       You will need to assess the appropriate location for the "dataMapFields" and create a binding in consequence (or use the Loaded event of the ComboBox to manually load the ItemsSource in code-behind.

    Marc Laroche
    Software Developer
    Xceed Software Inc.


    I don’t suffer from insanity, I enjoy every minute of it. - Unknown
  •  05-14-2008, 10:23 PM Post no. 12285 in reply to 12243

    Re: How to bind a DataTable to a ComboBox in WPF DataGrid?

    Hi Marcus,

    I am bit confused here.

        I do ask because I notice that the binding to load the ComboBox ItemsSource refers to a Binding to a "dataMapFields" on the DataContext.

       <ComboBox ItemsSource="{Binding dataMapFields}"

       If there is no "dataMapFields" property on the Cell`s Content, then it is normal that you are not seeing anything in the combo box.

     "dataMapFields" is a DataTable and how could I assign that to the Cell's Content. Leave my code. Could you please give a sample code that a ComboBox Cell which loads from a DataTable where the DataTable is in the code behind. I am trying to get the answer for this question from very beginning. But everybody is pointing to an existing example which come with DataGridControl. That example is using DataTable from App context. I hope I explained my issue clearly.

     


    Venkatesh Mookkan
  •  05-15-2008, 8:31 AM Post no. 12297 in reply to 12285

    Re: How to bind a DataTable to a ComboBox in WPF DataGrid?

    Venkatesh:

    Could you please give a sample code that a ComboBox Cell which loads from a DataTable where the DataTable is in the code behind. I am trying to get the answer for this question from very beginning. But everybody is pointing to an existing example which come with DataGridControl. That example is using DataTable from App context.

    Application.Current is just the location I chose to place the property that exposes my data source. That said, you can have your property anywhere as long as the grid has access to it. For example, if you have a Window1 that contains  your grid, you could do an AncestorType binding to find the window and get the property.

    {Binding RelativeSource={RelativeSource AncestorType={x:Type local:MainWindow}}, Path=dataMapFields}

    This binding assumes that you have declared an xmlns named local for your local namespace.

     


    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  05-16-2008, 7:01 AM Post no. 12323 in reply to 12297

    Crying [:'(] Re: How to bind a DataTable to a ComboBox in WPF DataGrid?

    Jenny,

    I feel bad asking you again and again with the same problem. I had changed the binding as you mentioned by no use.

     <xceed:CellEditor x:Key="SourceFieldEditStyle">
                <xceed:CellEditor.EditTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" AllowDrop="True">
                            <ComboBox ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:DataMapWindow}}, Path=dataMapFields}" SelectedValue="{xceed:CellEditorBinding}"  DisplayMemberPath="field_name" SelectedValuePath="field_name" HorizontalAlignment="Stretch"/>
                    </StackPanel>
                    </DataTemplate>
                </xceed:CellEditor.EditTemplate>
            </xceed:CellEditor>

     
    Is there anything, that I could send you, so that you can find the problem easily?
     


    Venkatesh Mookkan
  •  05-19-2008, 10:54 AM Post no. 12362 in reply to 12297

    Re: How to bind a DataTable to a ComboBox in WPF DataGrid?

    Hi Jenny,

    Let's see you have a WPF project with

    • Window1 form in namespace NS
    • In the Window1 codebehind, you have a dynamically filled DataTable named DT with 2 columns, ID and NAME
    • In Window1 you have a Grid named GRID
    • In GRID you have a column called COL with type of int refers to the DT/ID column
    • You want to display a combobox in GRID/COL showing DT/NAME with DT/ID as value
    Please write all the necessary codes in XAML (especially the Bindings everywhere!) and in C# that is needed to solve this problem. I'd like to ask you not to suggest to me any sample codes because in those there are pre-filled into-dll-compiled datasets what are so far away from reality.

    Thanks in advance, hope you can help because it's been very long to solve this problem,
    Peter 

Page 1 of 2 (17 items)   1 2 Next >
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.