GridViewDropDownCell can't dropdown in Ansys.UI.Toolkit.TableLayoutPanel

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 :

Best Answer

Answers

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 241
    First Anniversary First Comment 5 Likes Ansys Employee

    @1990chs , is there a reason you are not using a combo box control for your drop down?
    It looks like you are taking some of this UI code from the bolt tools add on modules. I would suggest looking at the WizardControlsV2.py file for some examples of a drop down UI. There is also an InputPanel class that is built to streamline building of wizard-like panels with user inputs.

    All these files are available in the bolt tools add on directory that can be found after loading the bolt tools add on, which uses the ACT extension framework.

  • 1990chs
    1990chs Member Posts: 34
    First Comment Name Dropper
    edited January 13

    @Mike.Thompson
    I try build a tool to assess the bolt average utilization. For different bolts type, the dangerous cross section is different, some are the shank cross section and some are screw cross section. I want to use the GridViewDropDownCell to choose different type to control the pitch column ReadOnly property which is only required by screw cross section.
    I have solved the dropdown click by using window control replace TableLayoutPanel control.
    But I have another problem is the Gridview seems no such dropdown selectchanged event as I described in another problem "https://discuss.ansys.com/discussion/2871/gridviewdropdowncell-selectedchanged-event#latest"
    Ps: I have search the all these files are available in the bolt tools within workbench. No GridViewDropDownCell information.
    I use the Gridview to shown the table and the C# DateGridView can't not add to the panel.

  • 1990chs
    1990chs Member Posts: 34
    First Comment Name Dropper

    @Mike.Thompson said:
    @1990chs , is there a reason you are not using a combo box control for your drop down?
    It looks like you are taking some of this UI code from the bolt tools add on modules. I would suggest looking at the WizardControlsV2.py file for some examples of a drop down UI. There is also an InputPanel class that is built to streamline building of wizard-like panels with user inputs.

    All these files are available in the bolt tools add on directory that can be found after loading the bolt tools add on, which uses the ACT extension framework.

    Hello,
    1. In the bolt tools in the ACT extension, the xml file is missing. Can you send me the whole source code ?
    2. In the bolt tools python file, there are two different version script such as WizardControls.py and WizardControlsV2.py file. So I want to know what's different with them ?