回复 19楼q406157290的帖子
:-| 控件不是万能的......C1FlexGrid主要是在DraggedColumn事件之后又会触发SelectedChanged事件,所以想了如下解决办法:
除了加上之前的那些事件,把DataGrid的ColumnReordering事件和ColumnReordered事件换成C1FlexGrid的DraggingColumn事件和DraggedColumn事件,并仍在DraggingColumn事件里调用SaveSelection方法保存选中状态;然后在DraggedColumn事件里标记当前是拖动状态结束,并在C1FlexGrid的SelectedChanged事件里对该状态进行判断处理,如果为true则调用RetainSelection方法回复选中状态即可;
参考代码如下:
- List<int> hashCode = new List<int>();
- private bool m_DraggedFlag = false;
- public void SaveSelection()
- {
- hashCode.Clear();
- foreach (var info in flex.SelectedItems)
- {
- hashCode.Add(info.GetHashCode());
- }
- }
- public void RetainSelection()
- {
- flex.SelectionChanged -= flex_SelectionChanged;
- if (hashCode.Count > 0)
- {
- flex.SelectedItems.Clear();
- }
- foreach (var row in flex.Rows)
- {
- int code = row.DataItem.GetHashCode();
- if (hashCode.Contains(code))
- {
- row.Selected = true;
- }
- }
- flex.SelectionChanged += flex_SelectionChanged;
- }
- private void flex_DraggingColumn(object sender, CellRangeEventArgs e)
- {
- SaveSelection();
- }
- private void flex_DraggedColumn(object sender, CellRangeEventArgs e)
- {
- m_DraggedFlag = true;
- }
- private void flex_SelectionChanged(object sender, CellRangeEventArgs e)
- {
- if (m_DraggedFlag)
- {
- RetainSelection();
- m_DraggedFlag = false;
- }
- }
复制代码
其他事件照旧,如果需要的话; |