Getting Serial Port Information

I tried so many solutions on here that didn’t work for me, only displaying some of the ports. But the following displayed All of them and their information. using (var searcher = new ManagementObjectSearcher(“SELECT * FROM Win32_PnPEntity WHERE Caption like ‘%(COM%'”)) { var portnames = SerialPort.GetPortNames(); var ports = searcher.Get().Cast<ManagementBaseObject>().ToList().Select(p => p[“Caption”].ToString()); var portList = … Read more

Grouping items in a ComboBox

It is possible. Use a ListCollectionView with a GroupDescription as the ItemsSource and just provide a GroupStyle to your ComboBox. See sample below: XAML: <Window x:Class=”StackOverflow.MainWindow” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” xmlns:local=”clr-namespace:StackOverflow” xmlns:uc=”clr-namespace:StackOverflow.UserControls” Title=”MainWindow” Height=”350″ Width=”525″> <StackPanel> <ComboBox x:Name=”comboBox”> <ComboBox.GroupStyle> <GroupStyle> <GroupStyle.HeaderTemplate> <DataTemplate> <TextBlock Text=”{Binding Name}”/> </DataTemplate> </GroupStyle.HeaderTemplate> </GroupStyle> </ComboBox.GroupStyle> <ComboBox.ItemTemplate> <DataTemplate> <TextBlock Text=”{Binding Name}”/> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> … Read more

Getting selected value of a combobox

Try this: private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { ComboBox cmb = (ComboBox)sender; int selectedIndex = cmb.SelectedIndex; int selectedValue = (int)cmb.SelectedValue; ComboboxItem selectedCar = (ComboboxItem)cmb.SelectedItem; MessageBox.Show(String.Format(“Index: [{0}] CarName={1}; Value={2}”, selectedIndex, selectedCar.Text, selecteVal)); }

Why can’t I select a null value in a ComboBox?

Well I recently ran into the same problem with null value for ComboBox. I’ve solved it by using two converters: For ItemsSource property: it replaces null values in the collection by any value passed inside converter’s parameter: class EnumerableNullReplaceConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var collection … Read more

How can I dynamically change auto complete entries in a C# combobox or textbox?

I had the same problem, and found an extremely simple workaround. As everybody else here, I couldn’t find any means to control de behaviour of the component, so I had to accept it. The natural behaviour is: you can’t dynamically populate the list every time the user types into the text box. You have to … Read more

How do I set combobox read-only or user cannot write in a combo box only can select the given items? [duplicate]

Just change the DropDownStyle to DropDownList. Or if you want it completely read only you can set Enabled = false, or if you don’t like the look of that I sometimes have two controls, one readonly textbox and one combobox and then hide the combo and show the textbox if it should be completely readonly … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)