Home Forums WPF controls Xceed DataGrid for WPF Questions on binding at run time

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

    Hi, I am trying to use the grid in a scenario where I do not want to bind it until run time. I am using some custom objects for data, the particular one here is very straightforward, just 3 properties, and it implements INotifyPropertyChanged. I have a List<> of these objects, then a CollectionView over that for sorting. I then set the GridViewControl.ItemsSource equal to my CollectionView. Also, I have enabled an InsertionRow because most of the time, this grid will start out empty and be used to input new data. But I am running into a couple of issues with this.

    1. 2 of the 3 fields are numeric (decimal to be exact), but no matter what I try, I cannot get any sort of editor to come up on the numeric fields. I can click in them, but I can never type in them.

    2. The other field is an integer, but it’s a key to another collection, and I want to display a drop down for the user. I have gotten the drop down to show up by following one of the samples; however, it is always empty, because I can not figure out how to set its ItemsSource at runtime.

    Thanks for your help,
    Futzy
    Spulzie LLC
    http://www.spulzie.com

    Imported from legacy forums. Posted by Ian (had 4708 views)

    Xceed Support
    Member
    Post count: 5658

    1. I am not able to reproduce this particular issue, can you provide some additional details:

    – Are your creating the columns manually? (AutoCreateColumns = false). If yes, can you post the code used to create them.
    – What are the “EditTriggers” set on the grid control?
    – What are the “CellEditorDisplayConditions” set on the grid control?

    2.

    If the dynamic creation of everything is a must for you, then you should build you template dynamically as well…

    (see code in next post)

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

    Xceed Support
    Member
    Post count: 5658

    <code>
    FrameworkElementFactory comboBox = new FrameworkElementFactory( typeof( ComboBox ) );
    comboBox.SetValue( ComboBox.SelectedValuePathProperty, “myIntegerKeyProperty” );
    comboBox.SetValue( ComboBox.DisplayMemberPathProperty, “myDescriptionProperty” );
    comboBox.SetValue( ComboBox.ItemsSourceProperty, myCollectionOfKeyDescriptionItems );

    CellEditorBindingExtension cellEditorBinding = new CellEditorBindingExtension();
    comboBox.SetBinding( ComboBox.SelectedValueProperty, cellEditorBinding.ProvideValue( null ) );

    CellEditor myDynamicEditor = new CellEditor();
    myDynamicEditor.EditTemplate = new DataTemplate();
    myDynamicEditor.EditTemplate.VisualTree = comboBox;

    myColumn.CellEditor = myDynamicEditor;
    </code>

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

    User (Old forums)
    Member
    Post count: 23064

    Thanks, the code for setting up the combo box worked great. Here’s how I’m defining my grid:

    <xcdg:DataGridControl Grid.Column=”0″ Grid.ColumnSpan=”4″ Grid.Row=”4″ Margin=”4″ Name=”BidAssignmentListX” SelectionMode=”Single”>
    <xcdg:DataGridControl.View>
    <xcdg:TableView>
    <xcdg:TableView.Theme>
    <xcdg:AeroNormalColorTheme />
    </xcdg:TableView.Theme>
    </xcdg:TableView>
    </xcdg:DataGridControl.View>

    <xcdg:DataGridControl.Columns>
    <xcdg:Column FieldName=”PlayerID” Title=”Player” DisplayMemberBinding=”{Binding Path=PlayerID}” />
    <xcdg:Column FieldName=”Amount” Title=”Bid Amount” DisplayMemberBinding=”{Binding Path=Amount}” />
    <xcdg:Column FieldName=”Percentage” Title=”Bid %” DisplayMemberBinding=”{Binding Path=Percentage}” />
    </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>

    And now I have one more question. The ComboBox works great when editing, but then when I click in another cell, the display switches to the integer key instead of the text from the drop down. What’s the best way to set it up to also display the text when the editor isn’t active?

    Imported from legacy forums. Posted by Ian (had 483 views)

    Xceed Support
    Member
    Post count: 5658

    The reason why you cannot edit the “Decimal” values is that the Binding created for those columns uses the default mode, which seems to be “OneWay” for CLR properties…

    There is 2 ways I can help you fix this:

    1. Specify explicitly the mode:

    <xcdg:Column FieldName=”PlayerID” Title=”Player” DisplayMemberBinding=”{Binding Path=PlayerID, Mode=TwoWay}” />

    2. Do not specify the DisplayMemberPath at all:

    <xcdg:Column FieldName=”PlayerID” Title=”Player” />

    Note: When the AutoCreateColumns property is “True” (default value), the data grid control will automatically create the columns according the data object`s properties… Specifying a Column with a field name will allow you to override the properties for the column that was automatically created for the property with the FieldName specified.

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

    Xceed Support
    Member
    Post count: 5658

    As for the creation of a CellContentTemplate that displays data based on a relation, refer to the following thread for more details:

    <a href=”http://forums.xceed.com/forums/ShowPost.aspx?PostID=5611″>http://forums.xceed.com/forums/ShowPost.aspx?PostID=5611</a&gt;

    Basically: Refer to the “Solid Foundation” sample (see the Employee ID column), which provide example as well as some utility classes for that purpose.

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

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