I have the following problem with ComboBox (DropDownList). My settings for combo:
AutoCompleteMode: AutoCompleteMode.SuggestAppend
AutoCompleteSource: AutoCompleteSource.ListItems
DropDownStyle: ComboBoxStyle.DropDownList
This combobox have datasource from database.
`DisplayMember = "nombre";
ValueMember = "id";`
Now reproduction steps:
Focus and Popup (!) ComboBox, type for example 'dog' (at first element is selected 'ant' is selected, then 'dog' - which is fine) and then press Tab - Random value 'turtle' or anything is restored... no events of the value or index changed fired.. While debugging I see that on combobox Leave event value is still 'dog', but on DropDownClosed event it's switched back to 'turtle'. Nothing is fired in between.
I canĀ“t understand why the combobox change text randomly but in debug mode still correctly.
I need when tab using autocomplete feature, the combobox still on value and text when im press tab.
PD: this happen only in combobox with datasource from database and the other computer LOL. in my workstation it's fine.
Solution:
http://support.microsoft.com/kb/2868238/en-us
It's O.S error, for previous versions of windows 7 SP1.
Related
I have a win form project in c#, there is a combo box in a datagridview.
it has 2 items which added in design. when I run the program, the combo box is empty.
why? please help me
I added the items in Design mode and it doesn't show anything then I added items programatically and it doesn't work either.
Here is the code:
cbcCell = (DataGridViewComboBoxCell)dgvFolder.Rows[0].Cells[1];
cbcCell.Items.Add("cat");
cbcCell.Items.Add("dog");
Without too much information here, the likely problem here is that the ComboBox has the ReadOnly property set to true. You can fix this by going into Design View, click the little arrow that appears in the top left of the DataGridView, select Edit Column, select the appropiate column/cell, and change the ReadOnly property to false.
I have a problem with the datagridview in c# forms. I have a combo box column in dgv1, when i select a value, the value isn't really selected until i press a button or a text field or anything else. The odd thing that when i press on the tool strip menu, the box in the dgv1 is not losing focus, so for example i select a value in the combo box , and then i press File->Save i get an error.
I read other questions similar to mine and I saw that the problem might be with validation.
I tried to add this.Validate(); in the cell end edit function for the dgv, but that didn't work.
I also tried to add that in the tool strip menu click event, validating the dgv, refreshing it and many other function, but nothing seems to work.
The problem is solved. I added datagridview.endedit() in the save button in the toolstrip. Works fine now.
I am using a simple ComboBox in C#. I put in 3 items: "apple", "banana", and "orange". Here is what I do:
Click on the comboBox to view the drop-down. I see all 3 items fine. Then I select "banana" via mouse-left-click
The comboBox now shows "banana" which is correct so far
Now I click on the comboBox again to view the drop-down. I move my mouse to highlight "orange". I then hit TAB to move off the comboBox
The comboBox is still showing "banana"
However, when I get the selectedItem, it's "orange"
Is this the expected behaviour? If I hightlight "orange" and tab out, I would expect either:
selectedItem should remain the same (meaning tab out does not trigger a selection change) or...
the comboBox should display "orange" since the selection has changed
I overcome this by using the comboBox.Leave event handler to manually set the text field to be the selectedItem however, I would like to know if I am missing some fundamental concepts here.
It seems logical that if selection changes, the comboBox.Text should reflect this without any manual intervention?
I believe you have it figured out correctly. In a combobox, the selecteditem does not have to be the same as the text. This allows non-items to be entered in the text of the combobox. You can just ignore the SelectedItem and use the text field.
So one particular behavior of the XAML combobox in WinRT is causing me a huge headache, because my client sees it as a defect, and doesn't care if it's the behavior of the control, he wants it changed. However, I cannot find anything that tells how to change it. The behavior I'm speaking of is that when nothing is selected the ComboBox popup opens displaying the ItemsSource in the middle of the list. I have a sorted list of countries, with the exception of US, UK, CAN being at the top. These 3 items are the most often selected items and the client wants them on top rather than having to scroll through the list to find them. That's easy enough, but because the list opens in the middle, you still have to scroll quite a bit to get to them. Is there some property I'm missing that turns this behavior off? I was able to finally convince them that the CarouselPanel wasn't a defect, but this one isn't going to fly.
Thanks in advance!
UPDATE:
So this combobox is databound through a ViewModel. in this instance, the ViewModel has no value (it is an empty string) for that particular property and so the Combobox shows empty, which is fine and desirable. When you click on the Combobox to select a value, it displays the list in the middle of the available values. this is the behavior that is undesirable. it should be showing the 1st value in the list at the top!
Well, one would think that the out of the box Combobox (there is no other built in dropdown control) would be able to work like any other combobox control in any other MS technology to date, but of course this is MS, so why should things be consistent. At any rate, I ended up having to create a "blank" entry and pre-select that item if the value in the VM is empty, and then write code in the setter of that property to ignore if "blank" item if it is selected. It's kludgy and wreaks of code smell, but it works
When you set the SelectedItem property to an object, the ComboBox attempts to make that object the currently selected one in the list. If the object is found in the list, it is displayed in the edit portion of the ComboBox and the SelectedIndex property is set to the corresponding index. If the object does not exist in the list, the SelectedIndex property is left at its current value.
Specifically, in my original design, I had Text comments in my ComboBox at load-up time, but then realised that users could type into the box, so I changed the DropDownStyle to DropDownList. Unfortunately, whilst this prevents the user from typing into the box, it also removes the Text from my VS2010 design and also ignores my C# updates to the Text in the program.
Is this normal behaviour or do I have a problem, or do I need to do this via another parameter ?
Keep your DropDownStyle on DropDown.
now on KeyPress event add the following:
e.Handled = true;