C# 将光标定位在GridViewComboxColumn(Telerik)中
我使用的是一个RadGridView,里面有一个视图GridViewComboxs列。 编辑器本身是一个基于以下内容的自定义编辑器:RadDropDownListEditor 我目前正在尝试实现它,以便按向左或向右箭头不会影响单元格或选择项,而是在编辑器中移动光标。因此,我的问题是如何访问光标的位置C# 将光标定位在GridViewComboxColumn(Telerik)中,c#,winforms,telerik,datagridcomboboxcolumn,C#,Winforms,Telerik,Datagridcomboboxcolumn,我使用的是一个RadGridView,里面有一个视图GridViewComboxs列。 编辑器本身是一个基于以下内容的自定义编辑器:RadDropDownListEditor 我目前正在尝试实现它,以便按向左或向右箭头不会影响单元格或选择项,而是在编辑器中移动光标。因此,我的问题是如何访问光标的位置 class CustomizedDropDownEditor : RadDropDownListEditor { public override void OnKeyDown(Syst
class CustomizedDropDownEditor : RadDropDownListEditor
{
public override void OnKeyDown(System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == System.Windows.Forms.Keys.Left || e.KeyCode == System.Windows.Forms.Keys.Right)
{
//Customized left right arrow key behaviour
}
else
{
base.OnKeyDown(e);
}
}
我已经尝试了一些方法,但没有找到一种方法可以访问编辑器的文本框或其中的selectionstart
编辑:
尽管上面的代码截取了这些键,但左箭头键仍然会导致单元格离开(但右箭头键不会导致)。是否有可能避免这种情况,如果有,如何避免
Tnx.将编辑器的
EditorElement
属性强制转换为raddropdownsteditorelement
后,您可以访问编辑器的EditorElement属性中的文本。如果要在同一覆盖范围内执行此操作:
class CustomizedDropDownEditor : RadDropDownListEditor
{
public override void OnKeyDown(System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == System.Windows.Forms.Keys.Left || e.KeyCode == System.Windows.Forms.Keys.Right)
{
//Customized left right arrow key behaviour
int selectionStart = ((RadDropDownListEditorElement)this.EditorElement).SelectionStart;
int selectionLength = ((RadDropDownListEditorElement)this.EditorElement).SelectionLength;
}
else
{
base.OnKeyDown(e);
}
}
}
或者,如果您想从其他地方执行此操作,您可以通过网格的ActiveEditor
属性执行相同的操作(尽管我不认为您还想执行其他操作,因为编辑器当然会关闭并丢失您的文本选择!):
给出了一个当触发EndEdit
事件时访问文本的示例,您可能也会对此感兴趣。tnx最有效(如果右键设置selectionstart there+1,如果左键设置-1(向下至值0或向上至text.length),但刚刚发现左键仍然触发它离开单元格(向左移动1个字符后)。你知道如何停止这种行为吗?确保你也以完全相同的方式覆盖了OnKeyUp
,以击败基本行为。tnx在这方面运行良好。我会将该答案标记为已接受,并对其进行投票。似乎原始奖金已经过期(由于第一次我的RL问题无法测试它,因为这)我需要200个代表才能给你一个奖励(似乎没有办法)。tnx仍然。
private void RadGridView1_OnMouseLeave(object sender, EventArgs e)
{
int selectionStart = ((RadDropDownListEditorElement)((CustomizedDropDownEditor)radGridView1.ActiveEditor).EditorElement).SelectionStart;
}