我正在使用Infragistics UltraWinGrid(Win 9.1版本)。默认行为是允许用户将文本输入到单元格中。当从Excel电子表格复制多个单元格时,只有第一个单元格的数据将被粘贴到UltraWinGrid中。如何模仿Infragistics UltraWinGrid中的复制粘贴按键?
通过将UltraWinGrid单元格设置为不可编辑,可以轻松地更改粘贴多个单元格的行为CellClickAction.CellSelect;不幸的是,当你这样做时,你可能不会在单元格中输入数据。
所以我试图与InitializeLayout,KeyDown和按键响应事件来修改这些设置。
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的单元中?