Change Combobox column order at runtime


Author
Message
Aaron Young
Aaron Young
StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)
Group: StrataFrame Users
Posts: 277, Visits: 1.1K
Hi,



Is it possible to switch around the column order in a multi-column combobox at runtime? For example, I have a customer dropdown with two columns (accno and name). I normally show the accno on the left before the name. However, some users would like to see it the other way around so I would like to be able to do that at run time.



Can the columns be switched around at runtime?



Thanks,



Aaron
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
You could just have code to reset the appropriate property (not sure what its called) at runtime. Take a look in the designer file in the InitializeComponent method and you'll see it.
Aaron Young
Aaron Young
StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)
Group: StrataFrame Users
Posts: 277, Visits: 1.1K
Thanks Greg,



I should have included in my post but I originally tried changing the PopulationDataSourceSettings but it doesn't change the order. It looks like the combobox has to be reset in some way after the changes have been made and that is what I am missing.



Aaron
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Aaron,



You need to do the following:



Based on the desired configuration of the drop down:



1. Clear the Columns collection of the combo (always do this)

2. create desired columns with properties set

3. Add those columns to combo

4. Change the DropDownFormattingString property to match columns.



Here is some sample code:



Private Sub SetDropDownStyle(ByVal style As String)

  '-- Establish locals for our two columns. There is nothing to keep

  '   us from changing how many columns are are shown in the

  '   drop down, but we'll use two for both cases in this example.

  Dim MultiColumnItem1 As MicroFour.StrataFrame.UI.Windows.Forms.MultiColumnItem = New MicroFour.StrataFrame.UI.Windows.Forms.MultiColumnItem

  Dim MultiColumnItem2 As MicroFour.StrataFrame.UI.Windows.Forms.MultiColumnItem = New MicroFour.StrataFrame.UI.Windows.Forms.MultiColumnItem

  Dim ddFormatString As String = String.Empty



  '-- Based on some predetermined style, setup combo.

  Select Case style

    Case "P"

      '-- Show a phone number first, then the name. Name column is set wider.

      MultiColumnItem1.Name = "Phone"

      MultiColumnItem2.Name = "Name"

      MultiColumnItem2.Width = 120



      '-- Setup format string. These refer to display members setup in the

      '   population list settings of the combo. {0} is first name,

      '   {1} is last name and {2} is phone number.

      ddFormatString = "{2}|{0} {1}"



    Case "N"

      '-- Show the name first, then the phone number. Name column is set wider.

      MultiColumnItem1.Name = "Name"

      MultiColumnItem1.Width = 120

      MultiColumnItem2.Name = "Phone"



      '-- Setup format string.

      ddFormatString = "{0} {1}|{2}"

  End Select



  '-- Be sure to clear the existing columns so there are no conflicts with the new columns.

  Me.cboCustomers.Columns.Clear()



  '-- Add the new columns and set format string.

  Me.cboCustomers.Columns.AddRange(New MicroFour.StrataFrame.UI.Windows.Forms.MultiColumnItem() {MultiColumnItem1, MultiColumnItem2})

  Me.cboCustomers.PopulationDataSourceSettings.DropDownFormatString = ddFormatString

End Sub



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

  '-- Setup combo with "Phone Name" style for drop down.

  Me.SetDropDownStyle("P")



  '-- You need to requery for the settings to take effect. (settings define how the

  '   combo is filled, so they do nothing until it is refilled)

  Me.cboCustomers.Requery()

End Sub




Aaron Young
Aaron Young
StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)
Group: StrataFrame Users
Posts: 277, Visits: 1.1K
Thanks Greg. I will give this a try.

I really appreciate your time and help on this one Smile

Thanks again

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Any time. Let us know if you get it working.
Aaron Young
Aaron Young
StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)
Group: StrataFrame Users
Posts: 277, Visits: 1.1K
Thanks Greg, works a treat! Smile



Many thanks!
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Excellent! Glad you go it going.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search