【问题标题】:Find Editor inside Active cell (XamDataGrid) infragistics在活动单元格 (XamDataGrid) 中查找编辑器
【发布时间】:2015-04-22 13:09:20
【问题描述】:

如何在infragistics xamdatagrid中找到基于ActiveRecord或ActiveCell的cellvaluepresenter?

我尝试了下面的代码,但它在单元格值呈现器中给出了 null。

    private void grdGrid_RecordActivated(object sender,RecordActivatedEventArgs e)
    {          

  (grdGrid.ActiveRecord as DataRecord).Cells["fldDescription"].IsActive = true;

            Cell selectedCell = grdGrid.ActiveCell;

            CellValuePresenter cvp = CellValuePresenter.FromCell(selectedCell);

            cvp.Editor.StartEditMode();

}

这是绑定

<igDP:UnboundField  Name="fldDescription" Label="Description" BindingPath="TaskItemAction.Description" BindingMode="TwoWay">
                                                            <igDP:Field.Settings>
                                                                <igDP:FieldSettings CellClickAction="EnterEditModeIfAllowed" EditorStyle="{StaticResource textStyleKey}" EditorType="{x:Type editors:XamTextEditor}" EditAsType="{x:Type sys:String}" 
                                                        CellWidth="30" CellHeight="30" AllowEdit="True" Width="0.4*" Height="30" >

                                                                </igDP:FieldSettings>
                                                            </igDP:Field.Settings>

所以现在我想通过该事件找到已激活的记录并找到编辑器类型并启动编辑模式。

    private void GrdTaskItemAction_RecordActivated(object sender, RecordActivatedEventArgs e)
            {
    grdGrid.ExecuteCommand(DataPresenterCommands.StartEditMode);
} 

对我来说工作正常,但它正在为单元格而不是编辑器(其中的控件)调用编辑模式。

我想在激活的单元格中找到那个编辑器并使其开始可编辑类型。

【问题讨论】:

    标签: wpf wpf-controls infragistics xamdatagrid


    【解决方案1】:

    可以直接使用activerecord获取单元格。

     private void grdGrid_RecordActivated(object sender, Infragistics.Windows.DataPresenter.Events.RecordActivatedEventArgs e)
        {
            Cell selectedCell = (grdGrid.ActiveRecord as DataRecord).Cells["fldDescription"];
    
            CellValuePresenter cvp = CellValuePresenter.FromCell(selectedCell);
    
            cvp.Editor.StartEditMode();
        }
    

    【讨论】:

    • 对不起,我突然改变了我的问题,因为我注意到我没有使用上面提到的数据绑定设置的 cellvaluepresenter\
    【解决方案2】:

    您可以尝试使用GetChildCellValuePresenters() 方法从RecordActivatedEventArgs 获取它。

    var cellValuePresenters = ((DataRecordPresenter)e.Record).GetChildCellValuePresenters()
    

    然后你必须为你需要的cellValuePresenter 过滤数组。

    编辑: 更新了代码以获取 cellValuePresenter,忘记将其投射到 DataRecordPresenter。不过既然你说你的问题不一样,那我再研究一下。

    【讨论】:

    • 当我尝试编写 e.Record.GetChildCellValuePresenters() 时如何获得此方法,它在 RecordActivatedEventArgs 事件中不可用
    【解决方案3】:

    使用以下代码:(如果您已经拥有CellValuePresenter

          CellValuePresenter cvp = new CellValuePresenter();
    
            ValueEditor VE = Infragistics.Windows.Utilities.GetDescendantFromType(cvp, typeof(ValueEditor), true) as ValueEditor;
            if (VE != null)
            {
                VE.IsInEditMode = true;
            }
    

    Infragistics Lib 中的每个 Editor 都派生自 ValueEditor,因此将其用作 Editor 的引用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-20
      • 2015-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多