Populate dropdown entries based on previous selection?

Hi,

Is there a way I can populate a dropdown list based on the selection from a previous dropdown in the same frame.

Regards

J

This is a part of the code which i am using to get the dynamic population for dropdown.

###Create combo1######

gbs.Add( wx.StaticText(p, -1, “Version”),(9,0), (1,1), wx.ALIGN_LEFT | wx.ALL, 5)

self.Versioncombo1 = wx.Choice(p, size=(80, -1), choices=CVersion)

self.Versioncombo1.Bind(wx.EVT_CHOICE, self.onChoice)

gbs.Add( self.Versioncombo1, (9,1) )

######On choice, build combo2 based on selections

def onChoice(self, event):

p = wx.Panel(self, -1, style = wx.TAB_TRAVERSAL

wx.CLIP_CHILDREN

wx.FULL_REPAINT_ON_RESIZE

)

p.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)

gbs = self.gbs = wx.GridBagSizer(5, 5)

self.selectedchoice = self.Versioncombo1.GetStringSelection()

if self.selectedchoice == “2.5.0.2” :

gbs.Add( wx.StaticText(p, -1, “label1”),(12,10), (1,1), wx.ALIGN_LEFT | wx.ALL, 5)

self.Versioncombo2 = wx.Choice(p, size=(80, -1), choices=(‘a’,‘b’, ‘c’, ‘d’, ‘r’))

gbs.Add( self.Versioncombo2, (12,11) )

box = wx.BoxSizer()

box.Add(gbs, 0, wx.ALL, 10)

p.SetSizerAndFit(box)

self.SetClientSize(p.GetSize())

elif self.selectedchoice == “2.5.0.6” :

gbs.Add( wx.StaticText(p, -1, “label2”),(12,10), (1,1), wx.ALIGN_LEFT | wx.ALL, 5)

self.Versioncombo3 = wx.Choice(p, size=(80, -1), choices=(‘1’,‘2’, ‘3’, ‘4’, ‘5’))

gbs.Add( self.Versioncombo3, (12,11) )

box = wx.BoxSizer()

box.Add(gbs, 0, wx.ALL, 10)

p.SetSizerAndFit(box)

self.SetClientSize(p.GetSize())

The label for the dropdown2 changes each time i make the relevant changes in dropdown1.

However, the list of choices displayed is the same

Please let me know if we can work around this issue in any way

Thank you,

J

···

---------- Forwarded message ----------
From: Jaishri Kashyap kashyap.jaishri@gmail.com
Date: Thu, Mar 18, 2010 at 3:07 PM
Subject: Populate dropdown entries based on previous selection?

To: wxpython-users@googlegroups.com

Hi,

Is there a way I can populate a dropdown list based on the selection from a previous dropdown in the same frame.

Regards

J

I’ve attached one way to do it. Note that I’m on Windows XP, wxPython 2.8.10.1 and Python 2.5

combos.py (1.19 KB)

···

On Thu, Mar 18, 2010 at 4:37 AM, Jaishri Kashyap kashyap.jaishri@gmail.com wrote:

Hi,

Is there a way I can populate a dropdown list based on the selection from a previous dropdown in the same frame.

Regards

J

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Mike Driscoll

Blog: http://blog.pythonlibrary.org