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

Setting Columns and CellEditor from code-behind - problems with editing

Sort Posts: Previous Next
  •  06-19-2008, 3:57 AM Post no. 13073

    Setting Columns and CellEditor from code-behind - problems with editing

    Is there any particular reason CellEditor in following code will not work. I need to set columns of DataGridControl manually. When I do this columns are displayed properly but editing does not work at all.

    I have tested different cell editors (standard and read from resource), set AutoCreateColumns to true/false, surrounded column creation code with BeginInit/EndInit, invoked Items.Refresh() and set all ReadOnly properties to false. Nothing works.

    EditableGridTestWindow.xaml:

    <Window x:Class="EditableGridTest.EditableGridTestWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:xc="http://schemas.xceed.com/wpf/xaml/datagrid"
        Title="Editable Grid Test" Height="300" Width="400" Loaded="Window_Loaded">
        <DockPanel>
            <xc:DataGridControl x:Name="testEditableDataGrid" />
        </DockPanel>
    </Window>

    EditableGridTestWindow.xaml.cs:

    using System.Windows.Data;
    using Xceed.Wpf.DataGrid;

    namespace EditableGridTest
    {
        public partial class EditableGridTestWindow
        {
            private const int COLUMNS_COUNT = 5;
            private const int ROWS_COUNT = 10;

            private string[][] testData;

            private void LoadSimpleTestData()
            {
                if (testData == null)
                {
                    testData = new string[ROWS_COUNT][];

                    for (int i = 0; i < ROWS_COUNT; ++i)
                    {
                        testData[ i ] = new string[COLUMNS_COUNT];

                        for (int j = 0; j < COLUMNS_COUNT; ++j)
                            testData[ i ][j] = string.Format("{0}-{1}", i, j);
                    }
                }

                testEditableDataGrid.ItemsSource = testData;
            }

            private void CreateColumnsManually()
            {
                testEditableDataGrid.BeginInit();
                testEditableDataGrid.Columns.Clear();

                for (int i = 0; i < COLUMNS_COUNT; ++i)
                {
                    Column col = new Column(string.Format("Value{0}", i), string.Format("[{0}]", i),
                                            new Binding(string.Format("[{0}]", i)));

                    col.CellEditor = CellEditor.TextBoxEditor;

                    testEditableDataGrid.Columns.Add(col);
                }

                testEditableDataGrid.AutoCreateColumns = false;
                testEditableDataGrid.EndInit();
            }

            public EditableGridTestWindow()
            {
                InitializeComponent();
            }

            private void Window_Loaded(object sender, System.Windows.RoutedEventArgs e)
            {
                LoadSimpleTestData();

                CreateColumnsManually();
            }
        }
    }

    Filed under: , ,
  •  06-25-2008, 6:45 PM Post no. 13222 in reply to 13073

    Re: Setting Columns and CellEditor from code-behind - problems with editing

    In order for a CellEditor to work, the fields/properties representing the columns must be get;set;, the DisplayMemberBinding must be TwoWay, and the cell editor must be bound to the cell that it edits using a CellEditorBinding.

    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  01-28-2011, 2:36 PM Post no. 29700 in reply to 13222

    Re: Setting Columns and CellEditor from code-behind - problems with editing

    Can you show a code snippet of how to use CellEditorBinding?
  •  01-28-2011, 4:39 PM Post no. 29704 in reply to 29700

    Re: Setting Columns and CellEditor from code-behind - problems with editing

    Hi Kevin,

    The CellEditorBinding is used to bind to the underlying data. This is usually when providing a custom CellEditor for a Column.

    Examples:

       <xcdg:Column FieldName="someFieldName">
          <xcdg:Column.CellEditor>
             <xcdg:CellEditor>
                <xcdg:CellEditor.EditTemplate>
                   <DataTemplate>
                      <TextBox Text="{xcdg:CellEditorBinding}" ... />
                   </DataTemplate>
                </xcdg:CellEditor.EditTemplate>
             </xcdg:CellEditor>
          </xcdg:Column.CellEditor>
       </xcdg:Column>

       <!--
       <CheckBox IsChecked="{xcdg:CellEditorBinding}" ... />
       <ComboBox SelectedValue="xcdg:CellEditorBinding" ... />
       -->

     


    ** Quick Tip: Clients with an active support subscription should be sending their questions by email if they wish to benefit from the faster response time. Thanks!


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