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

Preventing AddNew Programmatically

Sort Posts: Previous Next
  •  10-18-2009, 11:10 PM Post no. 24570

    Preventing AddNew Programmatically

    Please bear with me - I'm learning how to use the datagrid as a trial user and have been searching the forums and docs for hours to no avail...

     I have a situation where if the user selects a certain item in a combobox outside of the grid, the grid should not allow new items to be added, but should still allow changes to items in it.  How can I do this in VB? 

    I have tried to hide the insertion row, but the only place I can get a reference to it is in the InsertionRowInitializing event, but that is raised after the user clicks in it, but I would like it to be hidden sooner than that.

    I am using a DataGridCollectionViewSource bound to a custom collection of objects that inherits the IBindingList interface.

    Thanks,

    Marcus

  •  10-19-2009, 2:09 AM Post no. 24572 in reply to 24570

    Re: Preventing AddNew Programmatically

    Hi Marcus.

     

    You can create insertion row programmatically and get the reference to insertion row in Loaded event ("this" is a descendant of Xceed GridControl):

    private InsertionRow insertionRow;

    //In constructor:

    this.View = new Xceed.Wpf.DataGrid.Views.TableView();

    this.View.UseDefaultHeadersFooters = false;

    // Add the column manager row
    DataTemplate columnManagerRowTemplate = new DataTemplate();
    columnManagerRowTemplate.VisualTree = new FrameworkElementFactory(typeof(ColumnManagerRow));
    this.View.FixedHeaders.Add(columnManagerRowTemplate);

    // Add the insertion row
    DataTemplate insertionRowTemplate = new DataTemplate();
    insertionRowTemplate.DataType = typeof(InsertionRow);
    insertionRowTemplate.VisualTree = new FrameworkElementFactory(typeof(InsertionRow));
    insertionRowTemplate.VisualTree.AddHandler(InsertionRow.LoadedEvent, new RoutedEventHandler(InsertionRowLoaded));
    this.View.FixedHeaders.Add(insertionRowTemplate);

     

    then:

     

    private void InsertionRowLoaded(object sender, RoutedEventArgs e)
    {
        if (this.insertionRow != sender)
        {
            this.insertionRow = sender as InsertionRow;
        }
    }

     

    Vit

    Filed under:
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.