Home Forums WPF controls Xceed DataGrid for WPF Dynamic ComboBox Celleditor

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

    I can’t use Xaml here and I am not finding many examples of doing databinding in c# but:
    I have a combobox I need to fill with dynamic information from the filesystem. I want to take that info and make it the cell editor for a column
    this is what I have so far (does not do anything)
    <code>
    FrameworkElementFactory fef = new FrameworkElementFactory(typeof(ComboBox));
    DataTemplate dt = new DataTemplate();
    Binding listBinding = new Binding();
    fef.SetBinding(ComboBox.ItemsSourceProperty, listBinding);
    listBinding.Path = new PropertyPath(“Items”);
    dataTemplate = new DataTemplate();
    dataTemplate.VisualTree = fef;
    dt.VisualTree = fef;
    CellEditor ce = new CellEditor();
    ce.EditTemplate = dt;

    userDG.Columns[“Module”].CellEditor = ce;
    </code>

    Imported from legacy forums. Posted by MiddleTommy (had 4668 views)

    User (Old forums)
    Member
    Post count: 23064

    What exactly do you want to do? Fill the combobox with a databinding source? Or edit some data with your combobox?

    In the first case, you’ll have to specify the source of your binding :
    listBinding.Source = …
    For example: listBinding.Source = new ObservableCollection<FileInfo> …

    In the second case, you’ll have to specify the XCeed binding in your data template. Check the CellEditorBinding class in the help

    Could you explain exactly what you want to do in order to correctly answer your question? 😉

    Imported from legacy forums. Posted by Tanguy (had 487 views)

    Xceed Support
    Member
    Post count: 5658

    As well, you can find some help in the following thread:

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

    While the cases are not a 100% match, it does cover most of the issues of creating a ComboBox editor in code.

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

    User (Old forums)
    Member
    Post count: 23064

    Like I said – the code I provided does not work worth a darn. I just thought it might give an idea of possibilities. what I need to do is:
    populate a combobox with dynamic data(through databinding or manual insertion)
    use that combo box as a cell editor
    I am looking for a generic example. Details of where the data comes from should be insignificant

    As for this forum I get the feeling most people are asking very specific questions which only apply to them selves and dont help others a whole lot. If xceed wants there wpf datagrid to become popular IMHO they should have more generic answers on the forum to teach someone to fish instead of just giving them a fish. As for everyone else Please ask simple generic questions to solve your problem and help the community.

    I dont know how to get more generic or simple than – Dynamic ComboBox CellEditor –

    Thank you for your posts, I will check to see if it helps me learn more about wpf and the datagrid.

    Imported from legacy forums. Posted by MiddleTommy (had 811 views)

    User (Old forums)
    Member
    Post count: 23064

    After much searching and trying to bind to a c# object I found the solution

    It seems microsoft wishes to make it very hard to create DataTemplates in c# code behind.
    they call it depreciated. So I figured Why rock the boat use Xaml for its best then use c# for its best.

    so in the resources to the parent object I created a data template like so(mostly copied from solid foundation example)
    <code>
    <xcdg:CellEditor x:Key=”ModuleCellEditor” :Name=”ModuleCellEditor”>
    <xcdg:CellEditor.EditTemplate>
    <DataTemplate>
    <ComboBox BorderThickness=”0″
    BorderBrush=”Transparent”
    Background=”Transparent”
    VerticalContentAlignment=”Top”
    SelectedValuePath=”Name”
    ItemsSource=”{Binding Source={StaticResource mlist}}”
    Text=”{xcdg:CellEditorBinding}” IsEditable=”True”>
    <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>
    </Grid.Resources>

    </code>

    But I couldn’t figure out how to bind an existing C# Collection object to the combobox ItemsSource. I messed with different combinations for hours of DataContext and {Binding} changes. None threw any errors but they didn’t work either. so I had the idea switch my concept around and instead of binding to c# from xaml to pretend to bind to a static resouce in xaml and then from c# add the resource like so
    <code>
    <em>
    modlist = ModuleFinder.List(“//plugins/”);
    this.Resources.Add(“mlist”, modlist);
    </em>
    </code>

    just be sure to add the resource before you call the InitializeComponent() (this loads the xaml)

    Imported from legacy forums. Posted by MiddleTommy (had 445 views)

    User (Old forums)
    Member
    Post count: 23064

    I forgot about setting up the editor for the column from c#.

    when you load your columns in c# (or code behind for the proper term):

    <code>

    CellEditor ce = LayoutRoot.Resources[“ModuleCellEditor”] as CellEditor;
    if(ce!=null)
    userDG.Columns[“Module”].CellEditor = ce;

    </code>

    you can only call this after InitializeComponent() has been called

    Imported from legacy forums. Posted by MiddleTommy (had 5688 views)

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