简体   繁体   English

如何跳过DevExpress ColumnView的CellValueChanging状态?

[英]How can I skip the CellValueChanging state of DevExpress ColumnView?

There are 2 distinct UI concept: CellValueChanging vs CellValueChanged. UI有2个不同的概念:CellValueChanging与CellValueChanged。

Quoted from DevExpress Documentation: 引用DevExpress文档中的内容:

The CellValueChanging event is raised each time the edited value is being changed (the user types or deletes a character, chooses a value from the dropdown list, etc.). 每次更改已编辑的值时都会引发CellValueChanging事件(用户键入或删除字符,从下拉列表中选择一个值,等等)。

On the other hand, CellValueChanged is raised when user had done cell editing by hitting enter or clicking outside of the active cell. 另一方面,当用户通过单击回车或在活动单元格外部单击完成单元格编辑时,将引发CellValueChanged。

Now my problem is, I have a combobox type column, and I want to always skip the CellValueChanging and make the change final. 现在我的问题是,我有一个组合框类型列,我想始终跳过CellValueChanging并使更改最终完成。 The current behavior is when user select an item from the combobox, the change doesn't take effect immediately(eg, the view will not be resorted as per the change). 当前行为是当用户从组合框中选择一个项目时,更改不会立即生效(例如,根据更改不会重新使用视图)。 The change is not accepted until user hit enter or click outside of the cell. 除非用户按下Enter键或在单元格外部单击,否则更改将不被接受。

---------------07/26/2013 2:25PM update--------------- --------------- 07/26/2013 2:25 PM更新---------------
Sorry that my previous question description misled everybody, so I'll rephrase it. 抱歉,我先前的问题描述误导了所有人,因此我将其重述。

Here is the current behavior: 这是当前行为:

Pic1: beginning state. Pic1:开始状态。 Rows are sorted alphabetically by Target. 行按目标字母顺序排序。
在此处输入图片说明

Pic2: Change the 2nd row value from B to D Pic2:将第二行的值从B更改为D
在此处输入图片说明

Pic3: After a single mouse left click on item D, the dropdown disappears and the cell value changes to D. However, the rows are not resorted Pic3:在项目D上单击鼠标左键之后,下拉列表消失,并且单元格值更改为D。但是,行未替换
在此处输入图片说明

Pic4: After clicking outside the cell or hitting enter, the rows are resorted. Pic4:在单元格外部单击或单击Enter后,将对行进行重新排序。
在此处输入图片说明

What I want to achieve is to skip the step in Pic3. 我要实现的是跳过Pic3中的步骤。 In other word, I want any changes committed immediately, without having to make an extra kepboard or mouse click. 换句话说,我希望立即提交所有更改,而无需进行额外的滑板或鼠标单击。

What I am showing here is a simplified example of my application. 我在这里显示的是我的应用程序的简化示例。 I can't move my CellValueChanged event handler logic to CellValueChanging or EditValueChanged because it would cause some errors. 我无法将CellValueChanged事件处理程序逻辑移至CellValueChanging或EditValueChanged,因为这会导致一些错误。

You want to make some UI change once user edit the cell value, right? 您要在用户编辑单元格值后进行一些UI更改,对吗? I think generally you have to give up handling the CellValueChanged event, but use the CellValueChanging Event instead: 我认为通常您必须放弃处理CellValueChanged事件,而应使用CellValueChanging事件来代替:

pseudocode: 伪代码:

HandleCellValueChanging(object sender, CellValueChangingEventArgs e) 
{
   // Get underlying object
   // and write the value direct into the object
   var rowObj = (YourType)gridview.GetRow(gridView.FocusedRowHandle);
   rowObj.TargetField = e.NewValue; // e.Value or e.NewValue, not sure

   // Then Do your UI effect
}

Another option is to use RepositoryItemEditor and handle the key-up and/or Mouse-up event instead. 另一种选择是使用RepositoryItemEditor并处理键盘向上和/或鼠标向上事件。

If you want to to catch the moment when an end-user changes some value in gridview's cell editor (eg select item in combobox), please handle the EditValueChanged event of a corresponding RepositoryItem. 如果您想抓住最终用户在gridview的单元格编辑器中更改某些值的时刻(例如,组合框中的选择项),请处理相应RepositoryItem的EditValueChanged事件。 To immediately post this value (make the changes final), you need to call the PostEditor method of a corresponding container: 要立即发布此值(使更改最终生效),您需要调用相应容器的PostEditor方法:

repositoryItemComboBox1.EditValueChanged += repositoryItemComboBox1_EditValueChanged;
//...
void repositoryItemComboBox1_EditValueChanged(object sender, EventArgs e) {
    gridView1.PostEditor();
    // do something else if it needed
}

Related example: E3234 - How to update a row's style immediately after a an inplace editor's value is changed 相关示例: E3234-如何在更改就地编辑器的值后立即更新行的样式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM