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.

  1. # -*- coding: utf-8 -*-
  2.  
  3. #region Globals and Initialize
  4. import clr
  5. clr.AddReference("Ans.UI")
  6. from Ansys.UI import *
  7. clr.AddReference("Ans.Utilities")
  8. clr.AddReference('Ans.UI.Toolkit')
  9. clr.AddReference("Ans.UI.Toolkit.Base")
  10. clr.AddReference("Ansys.ACT.Interfaces")
  11. import Ansys.ACT.Interfaces
  12. import Ansys.UI.Toolkit
  13. import Ansys.Utilities
  14. import os
  15.  
  16. from Ansys.UI.Toolkit import *
  17. from Ansys.UI.Toolkit.Base import *
  18. from Ansys.UI.Toolkit.Drawing import *
  19.  
  20. global DefaultPanelEnum
  21. global DefaultFont
  22.  
  23. DefaultPanelEnum = Ansys.ACT.Interfaces.Mechanical.MechanicalPanelEnum.Wizard
  24. DefaultFont = Ansys.UI.Toolkit.Drawing.Font("Times New Roman",10)
  25.  
  26. #endregion
  27.  
  28. class ControlFramePanel(Ansys.UI.Toolkit.TableLayoutPanel):
  29. """
  30. Panel to connect to Mechanical that can host any user control.
  31. Panel can have headers on it to help close the window and manage some GUI actions.
  32. """
  33. def __init__(self, Control, Title, ShowHeader = True):
  34. self.Pane = None #Mechanical Pane that is always there
  35. self.MechPane = None #Mechanical Pane that is created when attaching control control in it
  36. self.MechanicalPanelEnum = None
  37.  
  38. self.ImageLibrary = Ansys.UI.Toolkit.ImageLibrary() #Image library
  39.  
  40. self.PanelTitle = Title
  41. self.Control = Control
  42. self.Rows.Add(Ansys.UI.Toolkit.TableLayoutSizeType.Absolute, 25)
  43. self.Rows.Add(Ansys.UI.Toolkit.TableLayoutSizeType.Percent, 100)
  44. self.Columns.Add(Ansys.UI.Toolkit.TableLayoutSizeType.Percent, 100)
  45.  
  46. self.HeaderPanel = Ansys.UI.Toolkit.TableLayoutPanel()
  47. self.HeaderPanel.Rows.Add(Ansys.UI.Toolkit.TableLayoutSizeType.Percent, 100)
  48. self.HeaderPanel.Columns.Add(Ansys.UI.Toolkit.TableLayoutSizeType.Percent, 100)
  49. self.HeaderPanel.Columns.Add(Ansys.UI.Toolkit.TableLayoutSizeType.Absolute, 30)
  50.  
  51.  
  52. def AddCloseButton(ImageName, ButtonText, ToolTipText, Column):
  53. ImageName =ImageName
  54. Button = Ansys.UI.Toolkit.Button()
  55. Button.Click += self.CloseButtonClick
  56. Button.ToolTipText = ToolTipText
  57. self.HeaderPanel.Controls.Add(Button, 0, Column)
  58. return Button
  59.  
  60. self.ClosePanelButton = AddCloseButton("Close_Red", "Close", "Close Window",1)
  61.  
  62. self.InfoLabel = Ansys.UI.Toolkit.Label(Title)
  63. self.InfoLabel.Font = DefaultFont
  64. self.HeaderPanel.Controls.Add(self.InfoLabel, 0, 0)
  65.  
  66. if ShowHeader: self.Controls.Add(self.HeaderPanel, 0, 0)
  67. self.Controls.Add(Control, 1, 0)
  68.  
  69.  
  70. def AddPanelToMechanical(self, OpenPanel = True, HideCloseButton = True):
  71. """
  72. Routine to add the panel to Mechanical GUI
  73. """
  74. self.MechanicalPanelEnum = DefaultPanelEnum
  75. ExtAPI.UserInterface.AttachControlToPanel(self, self.MechanicalPanelEnum)
  76. ExtAPI.UserInterface.ShowPanel(self.MechanicalPanelEnum)
  77.  
  78.  
  79. def ShowPanel(self, ShowPanel = True, Select = True):
  80. self.MechPane.Show()
  81. if Select: self.Pane.Select()
  82. if ShowPanel: ExtAPI.UserInterface.ShowPanel(self.MechanicalPanelEnum)
  83.  
  84. def HidePanel(self, HidePanel = False):
  85. ExtAPI.UserInterface.HidePanel(self.MechanicalPanelEnum)
  86. Ansys.UI.Toolkit.Application.Quit()
  87.  
  88. def CloseButtonClick(self, Sender, Event):
  89. if Sender == self.ClosePanelButton:
  90. self.HidePanel(HidePanel=True)
  91.  
  92.  
  93. BoltGridView = GridView()
  94. dropDownCell = Ansys.UI.Toolkit.GridViewDropDownCell()
  95. DropDownItems = []
  96. DropDownItems.append(GridViewDropDownCell.GridViewDropDownItem('Shank'))
  97. DropDownItems.append(GridViewDropDownCell.GridViewDropDownItem('Screw'))
  98. dropDownCell.AddItems(System.Array[GridViewDropDownCell.GridViewDropDownItem](DropDownItems))
  99. dropDownCell.Text = 'Shank'
  100. BoltGridView.Cells.SetCell(0, 0, dropDownCell)
  101.  
  102.  
  103. Title = 'Bolt Assessment'
  104. FramPanel = ControlFramePanel(BoltGridView, Title)
  105. FramPanel.AddPanelToMechanical()

When dropdown the cell, the error is as following :

Welcome!

It looks like you're new here. Sign in or register to get started.

Best Answer

Answers

  • Member, Employee Posts: 385
    25 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭

    @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.

  • Member Posts: 46
    10 Comments First Anniversary Name Dropper
    **
    edited January 2024

    @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.

  • Member Posts: 46
    10 Comments First Anniversary 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 ?

Welcome!

It looks like you're new here. Sign in or register to get started.