在GridControl中启用单元格的就地编辑

时间:2015-01-28 13:16:46

标签: wpf devexpress gridcontrol

我想为GridControl中的单元格启用就地编辑。我在TableView和Columns上设置了AllowEditing属性,但是在单击单元格后仍然无法编辑单元格中的数据。在上下文菜单中仅启用“复制”。我找不到解决办法。

TableView中的NavigationStyle属性设置为“Cell”

我的xaml。

    <dx:PLinqInstantFeedbackDataSource x:Name="PLinqInstantFeedbackDataSource" ListSource="{Binding Path=TestCollectionSource}" DefaultSorting="Property1 ASC"/>
    <dxg:GridControl EnableSmartColumnsGeneration="True" ItemsSource="{Binding Path=Data, ElementName=PLinqInstantFeedbackDataSource}" SelectionMode="Cell" IsManipulationEnabled="True">
        <dxg:GridControl.View>
            <dxg:TableView AllowEditing="True" NavigationStyle="Cell" AllowFilterEditor="True" AlternateRowBackground="CornflowerBlue" ShowAutoFilterRow="True" />
        </dxg:GridControl.View>
        <dxg:GridControl.Columns>
            <dxg:GridColumn FieldName="Property1" AllowEditing="True" ReadOnly="False" />
            <dxg:GridColumn FieldName="Number" AllowEditing="True" ReadOnly="False" />
        </dxg:GridControl.Columns>
    </dxg:GridControl>

修改

ViewModel和ListSource类

public class MainWindowViewModel : ObservableObject
{

    public MainWindowViewModel()
    {

    }

    private BindingList<TestClass> testCollection;
    public BindingList<TestClass> TestCollection
    {
        get
        {
            var result = this.testCollection;
            if (null == result)
            {
                lock(this)
                {
                    result = this.testCollection;
                    if (null == result)
                    {
                        result = new BindingList<TestClass>();
                        for (int i = 0; i < 1000000; i++)
                        {
                            result.Add(new TestClass() { Property1 = "test" + i, Number = i % 20 });
                        }

                        this.testCollection = result;
                    }
                }
            }
            return result;
        }
    }

    public IListSource TestCollectionSource
    {
        get { return new ListSource( ()=> this.TestCollection); }
    }
}
public class ListSource : IListSource
{
    public readonly Func<IList> innerListProvider;
    public ListSource(Func<IList> innerListProvider)
    {
        this.innerListProvider = innerListProvider;
    }
    public IList GetList()
    {
        return this.innerListProvider();
    }

    public bool ContainsListCollection
    {
        get { return false; }
    }
}

public class TestClass : ObservableObject
{
    private string property1;
    public string Property1
    {
        get { return this.property1; }
        set
        {
            this.property1 = value;
            RaisePropertyChanged(() => this.Property1);
        }
    }

    private int number;
    public int Number
    {
        get { return this.number; }
        set
        {
            this.number = value;
            RaisePropertyChanged(() => this.Number);
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我从DevExpress支持获得answer

  

PLinqInstantFeedbackDataSource是只读数据源。如果您希望直接在网格中编辑数据,请将源集合绑定到GridControl.ItemsSource属性,而不使用即时反馈数据提供程序。