How to use Ansys.UI.Toolkit GridView OnKeyDown event
Now I try to write a gridview table using Ansys.UI.Toolkit and add a paste function.
I found OnKeyDown event in Ansys.UI.Toolkit.GridView (in the following picture), but i don't know how to use it.
I try to use KeyEventDelegate, but it don't work.
# -*- coding: utf-8 -*- import clr clr.AddReference("Ans.UI.Toolkit") clr.AddReference("Ans.UI.Toolkit.Base") import Ansys.UI.Toolkit import Ansys.UI.Toolkit.Base import Ansys.UI.Toolkit.Drawing from Ansys.UI.Toolkit import * from Ansys.UI.Toolkit.Base import * from Ansys.UI.Toolkit.Drawing import * class Delete_APLX(Window): def __init__(self,ExtAPI,Transaction,MechanicalPanelEnum): self.Text = 'Apply Bolt Pretension Forces' self.Width = 550 self.ExtAPI = ExtAPI self.Transaction = Transaction self.MechanicalPanelEnum = MechanicalPanelEnum self.ErrorColose = False self._BuildUI() def _BuildUI(self): self.mainPanel = TableLayoutPanel() self.Add(self.mainPanel) self.mainPanel.Rows.Add(TableLayoutSizeType.Percent, 12.5) #0 self.mainPanel.Rows.Add(TableLayoutSizeType.Percent, 12.5) #1 self.mainPanel.Rows.Add(TableLayoutSizeType.Percent, 12.5) #2 self.mainPanel.Rows.Add(TableLayoutSizeType.Percent, 12.5) #3 self.mainPanel.Rows.Add(TableLayoutSizeType.Percent, 12.5) #4 self.mainPanel.Rows.Add(TableLayoutSizeType.Percent, 12.5) #5 self.mainPanel.Rows.Add(TableLayoutSizeType.Percent, 12.5) #6 self.mainPanel.Rows.Add(TableLayoutSizeType.Percent, 12.5) #7 # self.mainPanel.Rows.Add(TableLayoutSizeType.Absolute, 300) self.mainPanel.Columns.Add(TableLayoutSizeType.Percent, 25) #0 self.mainPanel.Columns.Add(TableLayoutSizeType.Percent, 25) #1 self.mainPanel.Columns.Add(TableLayoutSizeType.Percent, 25) #2 self.mainPanel.Columns.Add(TableLayoutSizeType.Percent, 25) #3 #--------------------------------------------------------------------------------------------- # Bolt GridVirew Setting # -------------------------------------------------------------------------------------------- self.BoltGridView = GridView() self.BoltGridView.ColumnCount = 6 self.BoltGridView.ColumnHeadersVisible = True self.BoltGridView.TextWrapEnabled = True self.BoltGridView.OnKeyDown += KeyEventDelegate(self.GridViewPaste) self.mainPanel.Controls.Add(self.BoltGridView, 2, 0, 5, 4) #Row 3, Column 1 To Row 7 Column 4 def GridViewPaste(self, sender, args): Text = Clipboard.GetDataObject().GetText().replace('\n','') qq = self.BoltGridView.SelectedCells[0].Text self.BoltGridView.SelectedCells[0].EditText = 'test' MessageBox.Show(qq) fram = Delete_APLX(ExtAPI,Transaction,MechanicalPanelEnum) fram.Run()
Best Answer
-
@Mike.Thompson said:
You need to point to a method like below. This method should have two tags: sender and event (self if used within a class as well).
The event properties will have things like which key is down, if shift is used etc…In the init function:
self.BoltGridView.OnKeyDown += MyKeyDownMethodLater in the class definition
def MyKeyDownMethod(self, sender, event):
passI have solved, the event should be KeyDown.
Also if we use Ansys.UI.Toolkit GridView, we should use the following code:
self.BoltGridView.KeyDown += KeyEventDelegate(self.GridViewPaste) def GridViewPaste(self, sender, args): pass
It is a little different with System.Windows.Forms.dll file.
0
Answers
-
You need to point to a method like below. This method should have two tags: sender and event (self if used within a class as well).
The event properties will have things like which key is down, if shift is used etc…In the init function:
self.BoltGridView.OnKeyDown += MyKeyDownMethodLater in the class definition
def MyKeyDownMethod(self, sender, event):
pass0