Welcome to the Xceed Community | Help
Community Search  
More Search Options

Problem in binding Combox as CellEditor / setting SelectedValueProperty through C# code

Sort Posts: Previous Next
  •  12-01-2009, 10:41 AM Post no. 25041

    Problem in binding Combox as CellEditor / setting SelectedValueProperty through C# code

    Hi..I am using Xceed DataGrid For WPF 3.5 professional edition.

    I am binding a combobox as cell editor through C# code and not throgh XAML. The selected value of the combobox is not retained in the cell after the edit. I want to set the SelectedValueProperty so that it will retain the selected value, but dont know what should i set it to?

    System.Windows.FrameworkElementFactory comboBox = new System.Windows.FrameworkElementFactory(typeof(Xceed.Wpf.Controls.NavigableComboBox));

    comboBox.SetValue(Xceed.Wpf.Controls.NavigableComboBox.ItemsSourceProperty, columnInfo.DomainValues.DefaultView);

    comboBox.SetValue(Xceed.Wpf.Controls.NavigableComboBox.DisplayMemberPathProperty, "DomainValue");

    comboBox.SetValue(Xceed.Wpf.Controls.NavigableComboBox.SelectedValuePathProperty, "DomainID");

    //comboBox.SetValue(Xceed.Wpf.Controls.NavigableComboBox.SelectedValueProperty, "Xceed.Wpf.DataGrid.CellEditorBinding"); ???

     

    dataGrid.Columns[columnInfo.Code].CellEditor = new CellEditor();

    dataGrid.Columns[columnInfo.Code].CellEditor.EditTemplate = new System.Windows.DataTemplate();

    dataGrid.Columns[columnInfo.Code].CellEditor.EditTemplate.VisualTree = comboBox;

    I have gone throgh lot of documentation and posts, but did not find 'what to set' in SelectedValueProperty, through C#. Please help.

  •  12-03-2009, 12:51 AM Post no. 25066 in reply to 25041

    Re: Problem in binding Combox as CellEditor / setting SelectedValueProperty through C# code

    Hello,

         Kindly find my explanation as below:

    Step 1:

    In Xaml, have the Combobox as Cell Editor in the Resources

    <xcdg:CellEditor x:Key="statusEditor">
                <xcdg:CellEditor.EditTemplate>
                    <DataTemplate>
                        <ComboBox BorderThickness="0"
                                x:Name="cmbStatus"
                                MinHeight="20"
                                VerticalContentAlignment="Top"
                                DisplayMemberPath="Enum_Value"
                                SelectedValuePath="Enum_ID"
                                Text="{xcdg:CellEditorBinding}" 
                                FocusVisualStyle="{x:Null}"
                                Loaded="ComboBox_Loaded"
                                SelectionChanged="cmb_SelectionChanged">
                            <ComboBox.Resources>
                                <Style TargetType="Popup">
                                    <Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
                                </Style>
                            </ComboBox.Resources>
                        </ComboBox>
                    </DataTemplate>
                </xcdg:CellEditor.EditTemplate>
                <xcdg:CellEditor.ActivationGestures>
                    <xcdg:TextInputActivationGesture/>
                </xcdg:CellEditor.ActivationGestures>
            </xcdg:CellEditor>

    Step 2: Declare the Columns as you want to bind the combobox to the above cell editor

      <xcdg:Column FieldName="Status" x:Key="colEntityStatus"  Title="Status" CellEditor="{StaticResource statusEditor}" >
            </xcdg:Column>

     

    Now all you have to do in the .cs file:

    Step 3

       protected void ComboBox_Loaded(object sender, RoutedEventArgs e)
            {
                ComboBox cmb = sender as ComboBox;

                if (cmb != null)
                {

                 cmb.SelectionChanged += new SelectionChangedEventHandler(cmb_SelectionChanged);
                                        cmb.ItemsSource = dt.DefaultView; //your itemssource
                                        if (drdgCurrentItem != null)
                                            cmb.SelectedValue = 123; //(Default value)

                }

     Step 4:

      protected void cmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                ComboBox cmb = sender as ComboBox;
                if (cmb != null)
                {
                    if (Convert.ToInt32(cmb.SelectedValue) > 0)
                    {

                        //you can make changes to the DataRowView which you are inserting or editing 

                       if (drdgCurrentItem != null)
                                    drdgCurrentItem["Entity_StatusID"] = cmb.SelectedValue;

               

                    }

     Thanks,

    Paras Sanghani

     


    Nothing Is Impossible
    Nothing Is Impossible
  •  04-29-2013, 5:25 AM Post no. 33274 in reply to 25066

    Re: Problem in binding Combox as CellEditor / setting SelectedValueProperty through C# code

    Hi Paras,

    I have a one related problem.

    I am tring to do like below

    <xcdg:CellEditor x:Key="ProductsCellEditor">

    <xcdg:CellEditor.EditTemplate>

    <DataTemplate>

    <Grid>

    <ComboBox ItemsSource="{Binding RelativeSource={RelativeSource Self}, Path=DataGridControl.DataContext.Products}"/>

    </Grid>

    </DataTemplate>

    </xcdg:CellEditor.EditTemplate>

    </xcdg:CellEditor>

    <xcdg:DataGridControl.Columns>

    <xcdg:Column FieldName="Product" Title="Product" ReadOnly="False" CellEditor="{StaticResource ProductsCellEditor}" TextWrapping="Wrap" Width="80" />

    </xcdg:DataGridControl.Columns>
     

    But its not able to see anything in the combobox. Its not populating the Products in editer.

    What is wrong here ?

    Thanks

    Ashish

     

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.