HOWTO:UltraWinGrid Cursor Movement like Excel

 HOWTO:UltraWinGrid Cursor Movement like Excel

http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=1997

Summary

In some user environments the user may need to have the UltraWinGrid move the cursor in a manner similar to Excel. The .PerformAction method of the UltraWinGrid provides the developer with almost unlimited flexibility when overriding the normal behavior.

Additional Information

Questions
How do I get UltraWinGrid to move the active cell with the cursor movement keys similar to Excel?

Solutions
Use .PerformAction to override the normal cursor movement behavior.

Step-By-Step Example

This sample project displays a sample financial DataTable and allows the user to move the cursor with the arrow keys:

This project consists of the following relevant code files:

clsAccounts.vb - clsAccounts.vb contains code used to create the sample DataTable. This code is not reviewed.

Form1.vb - Form1.vb contains the code relevant to this project and consists of the following regions:

Form Events

The Form Events region consists of the following event handlers:

MyBase.Load - The code in the Form Load event creates the sample DataTable and binds it to the grid:

' create DataTable and bind to grid
Dim accountData = New clsAccounts()
UltraGrid1.DataSource = accountData.MakeAccountsDataTable

UltraWinGrid Events

The UltraWinGrid Events region consists of the following event handlers:

UltraGrid1.KeyDown - The code in the KeyDown event invokes the appropriate .PerformAction methods for each of the cursor movement key strokes:

' perform action needed to move cursor
Select Case e.KeyValue

Case Keys.Up

UltraGrid1.PerformAction(ExitEditMode, False, False)
UltraGrid1.PerformAction(AboveCell, False, False)
e.Handled = True
UltraGrid1.PerformAction(EnterEditMode, False, False)

Case Keys.Down

UltraGrid1.PerformAction(ExitEditMode, False, False)
UltraGrid1.PerformAction(BelowCell, False, False)
e.Handled = True
UltraGrid1.PerformAction(EnterEditMode, False, False)

Case Keys.Right

UltraGrid1.PerformAction(ExitEditMode, False, False)
UltraGrid1.PerformAction(NextCellByTab, False, False)
e.Handled = True
UltraGrid1.PerformAction(EnterEditMode, False, False)

Case Keys.Left

UltraGrid1.PerformAction(ExitEditMode, False, False)
UltraGrid1.PerformAction(PrevCellByTab, False, False)
e.Handled = True
UltraGrid1.PerformAction(EnterEditMode, False, False)

End Select

UltraGrid1.InitializeLayout - The code in the InitializeLayout event sets the format of the currency columns and overrides the background color of the active cell:

' set format of currency columns
Dim intCol As Integer
For intCol = 2 To 13

e.Layout.Bands(0).Columns(intCol).Format = "c"

Next

' set background color of Active Cell
UltraGrid1.DisplayLayout.Override.ActiveCellAppearance.BackColor _
= Color.LightCyan

UltraGrid1.Enter - The code in the Enter event sets an Active Row and an Active Cell if they are not already set:

' set ActiveRow and ActiveCell on grid entry
If UltraGrid1.ActiveRow Is Nothing Then

UltraGrid1.ActiveRow _

= UltraGrid1.GetRow(Infragistics.Win.UltraWinGrid.ChildRow.First)

End If

If UltraGrid1.ActiveCell Is Nothing Then

UltraGrid1.ActiveCell = UltraGrid1.ActiveRow.Cells(2)

End If

Review
This sample project shows how to use the .PerformAction method of the UltraWinGrid to simulate the cursor movement of Excel.

Samples

 

 

ultrawingrid_tutorial_cursor_movement_like_excel.zip
 UltraWinGrid Tutorial Cursor Movement Like Excel
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值