Home Forums WPF controls Xceed DataGrid for WPF CellEditor for a String value:Wpf.Controls.AutoSelectTextBox

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #26450 |

    Hi all,

    I’m using a grid where the columns are created manually. I set grid.AutoCreateColumns = false;
    grid.ReadOnly = false;
    and all my columns has ReadOnly property set to false.

    Everything is fine when I try to edit a value of a column. The cell value is selected at mouse click, so this is ok. A problem occur when I add a new row to grid.
    My grid has a dataGridCollectionView = new DataGridCollectionView(DataSource) as ItemsSource.
    where DataSource is an IEnumerable.
    When I add a new data object to DataSource, then automatically a new row is added to the grid.
    It’s ok. BUT the cells value are nulls and I can not edit the value in this cells.
    I read a post where a man from Xceed tell that the problem occur if AutoCreateColumns = false and if is not specified a CellEditor for each column.
    So, for string columns I made a CellEditor like this:
    private CellEditor GetDefaultStringEditor()
    {
    CellEditor stringEditor = new CellEditor();
    DataTemplate dataTemplate = new DataTemplate();

    FrameworkElementFactory autoSelectTextBox = new FrameworkElementFactory(typeof(AutoSelectTextBox));
    Xceed.Wpf.DataGrid.Markup.CellEditorBindingExtension cellEditorBinding = new CellEditorBindingExtension();
    autoSelectTextBox.SetValue(AutoSelectTextBox.TextProperty, cellEditorBinding);
    autoSelectTextBox.SetValue(AutoSelectTextBox.BorderThicknessProperty, new Thickness(0));

    dataTemplate.VisualTree = autoSelectTextBox;
    stringEditor.EditTemplate = dataTemplate;
    return stringEditor;
    }

    But there are still another properties that must be set on AutoSelectTextBox, to look like default
    ( when mouse is over a row, than the height is increased and this look ugly; when click on a cell, the value is not selected like by default, ….)
    Can anybody help?

    The right way it was be that a Column object to have a DataType property and set automatically his default CellEditor like when AutoCreateColumns = true;

    Imported from legacy forums. Posted by winnetou (had 6444 views)

    Xceed Support
    Member
    Post count: 5658

    The problem seems to be in the creation of the DataTemplate for the CellEditor.

    Effectivelly, not only should the CellEditorBindingExtension be created, but it need to be applied over the property through FrameworkElementFactory.SetBinding…

    example:

    autoSelectTextBox.SetBinding( AutoSelectTextBox.TextProperty, cellEditorBinding.ProvideValue(null) );

    Imported from legacy forums. Posted by Marcus [Xceed] (had 587 views)

    User (Old forums)
    Member
    Post count: 23064

    Dim xcdGrid As New DataGridControl
    Dim DataTemplate As New DataTemplate
    Dim fef As New FrameworkElementFactory(GetType(ComboBox))
    Dim placeBinding As New Binding()
    fef.SetBinding(ComboBox.ItemsSourceProperty, placeBinding)
    placeBinding.Source = ds.Tables(0).DefaultView
    Dim binding1 As New Binding
    binding1.Source = ds.Tables(0).Columns(0).ToString
    fef.SetBinding(ComboBox.DisplayMemberPathProperty, binding1)

    Dim cellEditorBinding As New Xceed.Wpf.DataGrid.Markup.CellEditorBindingExtension()
    fef.SetBinding(ComboBox.SelectedValueProperty, cellEditorBinding.ProvideValue(Nothing))

    DataTemplate.VisualTree = fef

    Dim xcdCol As New Column
    xcdCol.FieldName = “CaptureSystemID”
    xcdCol.Title = “CaptureSystemID”

    Dim xcdEdit As New CellEditor
    xcdEdit.EditTemplate = DataTemplate
    xcdCol.CellEditor = xcdEdit
    xcdCol.CellContentTemplate = CreateTextDataTemplate(ds)
    xcdCol.CellEditorDisplayConditions = CellEditorDisplayConditions.MouseOverCell

    Dim xcdCol1 As New Column
    xcdCol1.FieldName = “CalendarDay”
    xcdCol1.Title = “CalendarDay”
    xcdCol1.CellEditorDisplayConditions = CellEditorDisplayConditions.MouseOverCell

    since i have created Data Template using above code but still i am unable to get the desired output as if we create Data Template in XAML and set its SelectedValue=”{xcdg:CellEditorBinding}” for combobox.
    Me getting nothing when i wil click on combobox.
    Plz help me in this regard as this requires t be done in my Ongoing project as sson as possible.

    xcdGrid.Columns.Add(xcdCol)
    xcdGrid.Columns.Add(xcdCol1)

    Imported from legacy forums. Posted by prashant (had 556 views)

    Xceed Support
    Member
    Post count: 5658

    Do you have any binding errors in the output window?

    Imported from legacy forums. Posted by Jenny [Xceed] (had 298 views)

    User (Old forums)
    Member
    Post count: 23064

    I am not getting any error but when i am trying to bind Integer value then i am not getting any selected value in combobox. when mouse is over combobox in any cell selected item wil be blank and when you wil select any item from combobox and move to another cell and come back to previous cell then again selected item wil be blank.
    whether only string values are supported?

    Imported from legacy forums. Posted by prashant (had 551 views)

    Xceed Support
    Member
    Post count: 5658

    If you use the same bindings (minus the CellEditorBinding) on a combobox outside the grid, are the values displayed?

    Imported from legacy forums. Posted by Jenny [Xceed] (had 555 views)

    User (Old forums)
    Member
    Post count: 23064

    Actually problem is whenver i wil bind any integer datacolumn to combobox in grid then it wil not highlight selected value in combobox..So whether i should convert integer value into string while getting from database?

    Imported from legacy forums. Posted by prashant (had 917 views)

    Xceed Support
    Member
    Post count: 5658

    An IValueConverter that converts an int to a string and vice-versa may solve the issue you are experiencing.

    The SolidFoundation sample also has an example of how to use a ComboBox as a cell editor for the “Ship Via” column.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 6883 views)

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.