I try to add a GridViewDropDownCell Gridview in TableLayoutPanel
But it seems can't work in TableLayoutPanel.
# -*- coding: utf-8 -*-
#region Globals and Initialize
import clr
clr.AddReference("Ans.UI")
from Ansys.UI import *
clr.AddReference("Ans.Utilities")
clr.AddReference('Ans.UI.Toolkit')
clr.AddReference("Ans.UI.Toolkit.Base")
clr.AddReference("Ansys.ACT.Interfaces")
import Ansys.ACT.Interfaces
import Ansys.UI.Toolkit
import Ansys.Utilities
import os
from Ansys.UI.Toolkit import *
from Ansys.UI.Toolkit.Base import *
from Ansys.UI.Toolkit.Drawing import *
global DefaultPanelEnum
global DefaultFont
DefaultPanelEnum = Ansys.ACT.Interfaces.Mechanical.MechanicalPanelEnum.Wizard
DefaultFont = Ansys.UI.Toolkit.Drawing.Font("Times New Roman",10)
#endregion
class ControlFramePanel(Ansys.UI.Toolkit.TableLayoutPanel):
"""
Panel to connect to Mechanical that can host any user control.
Panel can have headers on it to help close the window and manage some GUI actions.
"""
def __init__(self, Control, Title, ShowHeader = True):
self.Pane = None #Mechanical Pane that is always there
self.MechPane = None #Mechanical Pane that is created when attaching control control in it
self.MechanicalPanelEnum = None
self.ImageLibrary = Ansys.UI.Toolkit.ImageLibrary() #Image library
self.PanelTitle = Title
self.Control = Control
self.Rows.Add(Ansys.UI.Toolkit.TableLayoutSizeType.Absolute, 25)
self.Rows.Add(Ansys.UI.Toolkit.TableLayoutSizeType.Percent, 100)
self.Columns.Add(Ansys.UI.Toolkit.TableLayoutSizeType.Percent, 100)
self.HeaderPanel = Ansys.UI.Toolkit.TableLayoutPanel()
self.HeaderPanel.Rows.Add(Ansys.UI.Toolkit.TableLayoutSizeType.Percent, 100)
self.HeaderPanel.Columns.Add(Ansys.UI.Toolkit.TableLayoutSizeType.Percent, 100)
self.HeaderPanel.Columns.Add(Ansys.UI.Toolkit.TableLayoutSizeType.Absolute, 30)
def AddCloseButton(ImageName, ButtonText, ToolTipText, Column):
ImageName =ImageName
Button = Ansys.UI.Toolkit.Button()
Button.Click += self.CloseButtonClick
Button.ToolTipText = ToolTipText
self.HeaderPanel.Controls.Add(Button, 0, Column)
return Button
self.ClosePanelButton = AddCloseButton("Close_Red", "Close", "Close Window",1)
self.InfoLabel = Ansys.UI.Toolkit.Label(Title)
self.InfoLabel.Font = DefaultFont
self.HeaderPanel.Controls.Add(self.InfoLabel, 0, 0)
if ShowHeader: self.Controls.Add(self.HeaderPanel, 0, 0)
self.Controls.Add(Control, 1, 0)
def AddPanelToMechanical(self, OpenPanel = True, HideCloseButton = True):
"""
Routine to add the panel to Mechanical GUI
"""
self.MechanicalPanelEnum = DefaultPanelEnum
ExtAPI.UserInterface.AttachControlToPanel(self, self.MechanicalPanelEnum)
ExtAPI.UserInterface.ShowPanel(self.MechanicalPanelEnum)
def ShowPanel(self, ShowPanel = True, Select = True):
self.MechPane.Show()
if Select: self.Pane.Select()
if ShowPanel: ExtAPI.UserInterface.ShowPanel(self.MechanicalPanelEnum)
def HidePanel(self, HidePanel = False):
ExtAPI.UserInterface.HidePanel(self.MechanicalPanelEnum)
Ansys.UI.Toolkit.Application.Quit()
def CloseButtonClick(self, Sender, Event):
if Sender == self.ClosePanelButton:
self.HidePanel(HidePanel=True)
BoltGridView = GridView()
dropDownCell = Ansys.UI.Toolkit.GridViewDropDownCell()
DropDownItems = []
DropDownItems.append(GridViewDropDownCell.GridViewDropDownItem('Shank'))
DropDownItems.append(GridViewDropDownCell.GridViewDropDownItem('Screw'))
dropDownCell.AddItems(System.Array[GridViewDropDownCell.GridViewDropDownItem](DropDownItems))
dropDownCell.Text = 'Shank'
BoltGridView.Cells.SetCell(0, 0, dropDownCell)
Title = 'Bolt Assessment'
FramPanel = ControlFramePanel(BoltGridView, Title)
FramPanel.AddPanelToMechanical()
When dropdown the cell, the error is as following :
