DevExpress VerticalGrid EditorRow即时刷新与DisplayMember获取问题
DevExpress VerticalGrid LookUpEdit 即时刷新与DisplayMember获取问题解决
问题1:选择列表值后立即刷新EditorRow状态
默认情况下,VerticalGrid的单元格外观更改不会即时重绘,需在EditValueChanged事件中手动触发刷新操作。修改你的事件处理代码,在设置完背景色后调用RefreshRow方法即可让该行立即更新:
private void Ilue_zprstatus_EditValueChanged(object sender, EventArgs e) { LookUpEdit ilue = sender as LookUpEdit; if (ilue == null) return; string currentValue = ilue.EditValue?.ToString() ?? string.Empty; Color targetColor = Color.FromArgb(0xFF, 0xFF, 0xFF); switch(currentValue) { case "Green": targetColor = Color.FromArgb(0x99, 0xFF, 0x99); break; case "Yellow": targetColor = Color.FromArgb(0xFF, 0xFF, 0x99); break; } zpr_status.AppearanceCell.BackColor = targetColor; // 立即刷新当前EditorRow zpr_status.GridControl.RefreshRow(zpr_status); }
RefreshRow方法会强制VerticalGrid重绘指定行,无需等待单元格失去焦点就能看到颜色变化。
问题2:获取LookUpEdit的DisplayMember值
有两种常用方式获取当前选中项的显示文本(DisplayMember值):
方法1:使用GetDisplayText方法(最简单)
直接调用LookUpEdit的内置方法,传入当前编辑值即可得到对应的显示文本:
string displayText = ilue.GetDisplayText(ilue.EditValue);
方法2:通过选中的数据源行获取
如果需要直接从数据源对象中提取DisplayMember对应的属性值,可使用GetSelectedDataRow方法:
- 若数据源是自定义实体类(比如
ColorModel,其中ColorName是DisplayMember):
var selectedItem = ilue.GetSelectedDataRow() as ColorModel; if (selectedItem != null) { string displayText = selectedItem.ColorName; }
- 若数据源是
DataTable:
DataRowView rowView = ilue.GetSelectedDataRow() as DataRowView; if (rowView != null) { string displayText = rowView[ilue.Properties.DisplayMember].ToString(); }
内容的提问来源于stack exchange,提问作者liNkiN
相关产品推荐
相关产品推荐

