Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# WPF Combobox dropdown list to multiple columns

Is it possible to "force" the combobox items in list to appear in say two columns?

For example like this:

CB Selected Item

CB Item 1 | CB Item 4

CB Item 2 | CB Item 5

CB Item 3 |

like image 495
Kristo Avatar asked Feb 04 '13 13:02

Kristo


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C full form?

Full form of C is “COMPILE”.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

What is C language basics?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.


2 Answers

You can change the ItemsPanel to a WrapPanel, just be careful on the height (you could write a converter to calculate it according to the number of items) :

<ComboBox>
    <ComboBox.Resources>
        <Style TargetType="ComboBox">
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <WrapPanel IsItemsHost="True" Orientation="Vertical" Width="100" Height="50" />
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="ComboBoxItem">
            <Setter Property="Width" Value="50" />
        </Style>
    </ComboBox.Resources>

    <ComboBoxItem Content="Value 1" />
    <ComboBoxItem Content="Value 2" />
    <ComboBoxItem Content="Value 3" />
    <ComboBoxItem Content="Value 4" />
    <ComboBoxItem Content="Value 5" />
</ComboBox>
like image 197
mathieu Avatar answered Oct 17 '22 15:10

mathieu


Well, you can, here's the XAML:

<ComboBox Name="ComboBox">
    <ComboBox.ItemsPanel>
        <ItemsPanelTemplate>
            <UniformGrid Columns="2"/>
        </ItemsPanelTemplate>
    </ComboBox.ItemsPanel>
</ComboBox>

Now a simple test, adding numbers from 0 to 8 gives:

uniform grid in combo box

Now you can style it all you want... :)

Of course every item (every number, in this particular case) is separate, clickable item, just so there are no misunderstandings.

[EDIT] I have just noticed you want to do it 'the opposite way', that is in 'rows' direction, if so, then maybe it's better to use the WrapPanel instead, as someone suggested in the other answer. The UniformGrid fills the grid in the column-wise direction first.

Maybe there's a way to do it with UniformGrid, but there's no apparent and easy one-click change (I was wrong here before :) )

like image 6
Patryk Ćwiek Avatar answered Oct 17 '22 14:10

Patryk Ćwiek