如何通过复制和复制来模拟按键粘贴 Infragistics UltraWinGrid?
我正在使用 Infragistics UltraWinGrid(Win 9.1 版)。默认行为是允许用户在单元格中键入文本。当从 Excel 电子表格复制多个单元格时,只有第一个单元格的数据将粘贴到 UltraWinGrid 中。
通过使用 CellClickAction.CellSelect 将 UltraWinGrid 单元格设置为不可编辑,可以轻松更改粘贴多个单元格的行为;不幸的是,当您执行此操作时,您可能无法在单元格中键入数据。
因此,我尝试使用 InitializeLayout、KeyDown 和 KeyPress 事件修改这些设置。
private void ugridQuoteSheet_InitializeLayout(object sender, InitializeLayoutEventArgs e)
{
e.Layout.Override.AllowMultiCellOperations = AllowMultiCellOperation.All;
e.Layout.Override.CellClickAction = CellClickAction.CellSelect;
}
//Event used to circumvent the control key from choking in
//the KeyPress event. This doesn't work btw.
private void ugridQuoteSheet_KeyDown(object sender, KeyEventArgs e)
{
UltraGrid grid = (UltraGrid)sender;
if (e.Control == true)
{
e.SuppressKeyPress = true;
}
}
// This event comes after the KeyDown event. I made a lame attempt to stop
// the control button with (e.KeyChar != 22). I lifted some of this from
// the Infragistics post: http://forums.infragistics.com/forums/p/23690/86732.aspx#86732
private void ugridQuoteSheet_KeyPress(object sender, KeyPressEventArgs e)
{
UltraGrid grid = (UltraGrid)sender;
if ((grid != null) && (grid.ActiveCell != null) && (!grid.ActiveCell.IsInEditMode) && (e.KeyChar != 22))
{
grid.PerformAction(UltraGridAction.EnterEditMode);
EditorWithText editor = (EditorWithText)grid.ActiveCell.EditorResolved;
editor.TextBox.Text = e.KeyChar.ToString();
editor.TextBox.SelectionStart = 1;
}
}
// This puts the grid in CellSelect mode again so I won't edit text.
private void ugridQuoteSheet_AfterCellUpdate(object sender, CellEventArgs e)
{
this.ugridQuoteSheet.DisplayLayout.Override.CellClickAction = CellClickAction.CellSelect;
}
我现在可以再次在单元格中键入值。问题是,当我按 [ctrl][v] 进行粘贴时,KeyPressEventArgs.KeyChar 是 22 并且没有“v”。您可以在 ugridQuoteSheet_KeyPress 委托中看到我徒劳地尝试规避此问题。事件处理和 CellClickAction 设置的正确组合是什么,以允许复制粘贴和在 UltraWinGrid 的单元格中键入内容?
I am using the Infragistics UltraWinGrid (version Win 9.1). The default behavior is to allow the user to type text into a cell. When one copies multiple cells from an Excel spreadsheet, only the first cell's data will be pasted into the UltraWinGrid.
One can easily change the behavior to paste multiple cells by setting the UltraWinGrid cells to be uneditable with CellClickAction.CellSelect; Unfortunately when you do this you may not type data into the cells.
So I have attempted to modify these settings with the events for InitializeLayout, KeyDown, and KeyPress.
private void ugridQuoteSheet_InitializeLayout(object sender, InitializeLayoutEventArgs e)
{
e.Layout.Override.AllowMultiCellOperations = AllowMultiCellOperation.All;
e.Layout.Override.CellClickAction = CellClickAction.CellSelect;
}
//Event used to circumvent the control key from choking in
//the KeyPress event. This doesn't work btw.
private void ugridQuoteSheet_KeyDown(object sender, KeyEventArgs e)
{
UltraGrid grid = (UltraGrid)sender;
if (e.Control == true)
{
e.SuppressKeyPress = true;
}
}
// This event comes after the KeyDown event. I made a lame attempt to stop
// the control button with (e.KeyChar != 22). I lifted some of this from
// the Infragistics post: http://forums.infragistics.com/forums/p/23690/86732.aspx#86732
private void ugridQuoteSheet_KeyPress(object sender, KeyPressEventArgs e)
{
UltraGrid grid = (UltraGrid)sender;
if ((grid != null) && (grid.ActiveCell != null) && (!grid.ActiveCell.IsInEditMode) && (e.KeyChar != 22))
{
grid.PerformAction(UltraGridAction.EnterEditMode);
EditorWithText editor = (EditorWithText)grid.ActiveCell.EditorResolved;
editor.TextBox.Text = e.KeyChar.ToString();
editor.TextBox.SelectionStart = 1;
}
}
// This puts the grid in CellSelect mode again so I won't edit text.
private void ugridQuoteSheet_AfterCellUpdate(object sender, CellEventArgs e)
{
this.ugridQuoteSheet.DisplayLayout.Override.CellClickAction = CellClickAction.CellSelect;
}
I can now key in values into the cells again. The problem is, when I press [ctrl][v] for paste, the KeyPressEventArgs.KeyChar is 22 and there is no 'v'. You can see my futile attempt to circumvent this problem in the ugridQuoteSheet_KeyPress delegate. What is the right combination of event handling and CellClickAction setting to allow both Copy-Paste and typing into a cell of the UltraWinGrid?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仔细阅读之前提到的帖子( http:// forums.infragistics.com/forums/p/23690/86732.aspx#86732
)我已经能够解决这个问题了。
设置 UltraWinGrid.DisplayLayout.Override.CellClickAction = CellClickAction.CellSelect; 后,这一切都可以在 KeyPress 事件中处理。当然是在InitializeLayout事件中。
我不知道如何处理同时按下的按键,[ctrl][v]。 Char.IsControl(e.KeyChar) 在这里发挥了作用。
After a bit more careful reading of the post mentioned before ( http://forums.infragistics.com/forums/p/23690/86732.aspx#86732
) I have been able to tackle this problem.
This can be all handled within the KeyPress event after setting UltraWinGrid.DisplayLayout.Override.CellClickAction = CellClickAction.CellSelect; in the InitializeLayout event of course.
I was ignorant of how to handle the simultaneous key press, [ctrl][v]. The Char.IsControl(e.KeyChar) does the trick here.