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

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

  •  06-19-2008, 3:57 AM

    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();
            }
        }
    }

View Complete Thread
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.