Given 是运行时的 Telerik RadGrid for Winforms,多列和一些行代表一个组,其中一些折叠,一些展开。组可以嵌套。在折叠的组上拖动矩形似乎无法选择行。
是否可以在运行时通过鼠标拖动矩形来选择这些行,折叠和展开? 如果是这样,我该如何启用此功能?
最佳答案
RadGridView 中的鼠标选择在 RowBehavior 类中处理。您需要的特定类是 GridDataRowBehavior,因为选择是在数据行上执行的。因此,我创建了一个继承自默认行为的自定义行为类,并在默认选择后执行一些额外的代码。
public class CustomGridDataRowBehavior : GridDataRowBehavior
{
protected override bool ProcessMouseSelection(System.Drawing.Point mousePosition, GridCellElement currentCell)
{
bool result = base.ProcessMouseSelection(mousePosition, currentCell);
if (result)
{
List<GridViewRowInfo> orderedRows = new List<GridViewRowInfo>();
PrintGridTraverser traverser = new PrintGridTraverser(this.GridControl.MasterView);
traverser.ProcessHiddenRows = true;
traverser.ProcessHierarchy = true;
while (traverser.MoveNext())
{
orderedRows.Add(traverser.Current);
}
int minIndex = int.MaxValue;
int maxIndex = int.MinValue;
foreach (GridViewDataRowInfo selectedRow in this.GridControl.SelectedRows)
{
int rowIndex = orderedRows.IndexOf(selectedRow);
if (rowIndex > maxIndex)
{
maxIndex = rowIndex;
}
if (rowIndex < minIndex)
{
minIndex = rowIndex;
}
}
this.GridControl.ClearSelection();
for (int i = minIndex; i <= maxIndex; i++)
{
if (!orderedRows[i].IsSelected)
{
orderedRows[i].IsSelected = true;
}
}
}
return result;
}
}
现在要使用此行为,您需要注销默认行为并注册此行为。方法如下:
BaseGridBehavior behavior = this.radGridView1.GridBehavior as BaseGridBehavior;
behavior.UnregisterBehavior(typeof(GridViewDataRowInfo));
behavior.RegisterBehavior(typeof(GridViewDataRowInfo), new CustomGridDataRowBehavior());
关于c# - 在 Telerik RadGrid for Winforms 中选择包括折叠组在内的多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32051264/