in
Forums
Blogs
Files
Devexpress.Com
Client Center
Support Center
DevExpress Channel

[SOLVED] Grid not editable when bound from service

Last post 12/4/2008 11:25 AM by Sean Pointer. 1 replies.
Page 1 of 1 (2 items)
Sort Posts:
Previous Next
  • 11/26/2008 2:07 PM

    [SOLVED] Grid not editable when bound from service

    I'm trying to get an editable grid with a DataSource provided by a WCF Service.

    I can get an editable grid when the source is provided by a generic list, using the techniques shown in the Introduction Tutorial video.  However, when I change the DataSource assignment line, and replace it with my Service code call, the grid is correctly populated with data, however the cells are no longer editable.

    My XAML code is unchanged for both scenarios, and is as follows: 

     

    UserControl x:Class="TestGrid.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns
    :dx
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="740" Height="330" BorderBrush="Black" BorderThickness="3" >="clr-namespace:DevExpress.Windows.Controls;assembly=DevExpress.AgDataGrid.v8.2

    <Grid x:Name="LayoutRoot" Background="White">
      <dx:AgDataGrid x:Name="mygrid" >
       
    <dx:AgDataGrid.Columns></dx:AgDataGrid.Columns>
     
    </dx:AgDataGrid>
    </Grid>
    </
    UserControl>

    Very straight forward, nothing unusual.  Note: I seem to have to specify the columns manually when binding from a Service, but that isn't really a problem for me - although it isn't shown above.

    My CS code for the generic list (which works properly) is as follows:

    public Page()
    {
       InitializeComponent();

       mygrid.DataSource = Persons.GetAllPersons();

    }

    And when I change it to the service provided data source, the CS code becomes:

    public Page()
    {
        InitializeComponent();

        Service1Client servClient = new Service1Client();
        servClient.GetAllRecordsCompleted += new EventHandler<GetAllRecordsCompletedEventArgs>(servClient_GetAllRecordsCompleted);
        servClient.GetAllRecordsAsync();
    }
    void servClient_GetAllRecordsCompleted(object sender, GetAllRecordsCompletedEventArgs e)
    {          
        mygrid.DataSource = e.Result;
    }

    As I say, the data shows up just fine, but none of the fields are editable.  I have tried setting the AllowEditing flag for the grid as well as columns, in both the XAML and CS code.

    What do I need to do to get this grid to be editable?

  • 12/4/2008 11:25 AM In reply to

    Re: Grid not editable when bound from service

     Ok, I solved my own problem.

    In order for cell editing to work when the grid's datasource doesn't load immediately (such as when it loads on event or delayed, like with a service call), you need the following:

    - XAML must NOT have "AutoGenerateColumns" specified.
    - XAML must NOT have columns manually specified.
    - XAML MUST have the code: <dx:AgDataGrid.Columns></dx:AgDataGrid.Columns> included, however.
    - CS must have code in the following format:

        mygrid.DataSource = e.Result;
        mygrid.AutoGenerateColumns = true; 

    Notce that you must set AutoGenerateColumns to true, AFTER the datasource for the grid is specified!

    I'm really suprised its so picky about this in order for the user to be able to edit the grid cells.  Plus, if you don't want AutoGenerateColumns set to true, for whatever reason, you can't get the grid to edit.  I really don't understand why it's like this.

Page 1 of 1 (2 items)
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED