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

Programmticly adding columns/EditTemplates

Sort Posts: Previous Next
  •  02-26-2009, 10:38 PM Post no. 18950

    Programmticly adding columns/EditTemplates

    The project I am working on requires all controls to be added to the screen programmatically.

    I have tried creating a data grid with 2 columns one of which has an combo box edit template.

    The code below I copied from other forum posts and modified it to suit my own needs however when I try to edit a record/cell the combo box is not displayed at all.

    Does anyone know why or have any suggestions?

    Also i read somewhere that is not recommended to create this programmatically is this true? If it is true what are the risks and implications of doing it programmatically?

     this.xceedDataGrid.AutoCreateColumns = false;

    this.xceedDataGrid.EditTriggers = EditTriggers.CellIsCurrent;

    this.xceedDataGrid.CellEditorDisplayConditions = CellEditorDisplayConditions.MouseOverCell;

    Column titleCol = new Column("Title", "Title", new Binding("Title"));

    List<String> itemList = new List<String>();

    ObjectQuery<Course> courseQuery = schoolContext.Course;

    foreach (Course currentCourse in courseQuery)

    {

                    itemList.Add(currentCourse.Title.ToString());

    }

    Binding binding = new Binding();

    binding.Source = itemList;

     

    FrameworkElementFactory factory = new FrameworkElementFactory(typeof(ComboBox));

    factory.SetValue(ComboBox.ItemsSourceProperty, binding);

    CellEditorBindingExtension cellEditorBindingExtension = new CellEditorBindingExtension();

    factory.SetValue(ComboBox.SelectedValueProperty, cellEditorBindingExtension.ProvideValue(null) as BindingBase);

    DataTemplate editTemplate = new DataTemplate(typeof(ComboBox));

    editTemplate.VisualTree = factory;

    CellEditor cellEditor = new CellEditor();

    cellEditor.EditTemplate = editTemplate;

    titleCol.CellEditor = cellEditor;

    this.xceedDataGrid.Columns.Add(titleCol);

    this.xceedDataGrid.Columns.Add(new Column("OnlineCourse", "OnlineCourse", new Binding("OnlineCourse.URL")));

  •  03-02-2009, 8:01 PM Post no. 19002 in reply to 18950

    Re: Programmticly adding columns/EditTemplates

    Does anyone have any suggestions?

  •  03-03-2009, 10:24 AM Post no. 19008 in reply to 18950

    Re: Programmticly adding columns/EditTemplates

    Do you have any errors in your output window? Also, it is NOT recommended to work with templates in code but rather to define them all in XAML.
    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.