combobox items not show in datagridview - c#

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.

Related

Combobox dont show correctly text on tab

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.

WinRT XAML ComboBox opens in middle of list

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.

Change the style of the controls that are exposed when a Datagrid is in Edit mode

I am using a Library that has a class of type GanttChartDataGrid. For this question I am just concerned with the Datagrid. Currently, I used this code to acheive single click to edit in the grid. Single Click to Edit Code.
This works great, but the issue is, since my textboxes are in edit mode, they are exposed and you can see them. Making the datagrid look ugly here is a picture:
The cells under "Task" are all exposing their textboxes. In the next picture, I would like the cells to behave like how duration is. It shows it like a label within the grid and if it is not selected, once it becomes selected it displays the textbox.
I would like it to display the underlying textbox only when that row is selected.
Thanks!
I figured out my question.
I was databinding to Textboxes, I changed those to textblocks and now it works great.

C# Adding Combobox dynamically losing selected items in others Combobox

On a form, I have a default ComboBox, I have another button that allows user to add more ComboBoxes, however, when user adds new combobox dynamically, existing selected value in the default combo box changes, where as idea is however many ComboBoxes are added, every previously added ComboBox would not lose a selection if user has selected anything.
Can some one point in the right direction?
Thanks
You are not very clear on your problem, however I would suggest setting a new BindingContext to your Control, before adding it to the form.
Good luck.

WPF DataGrid can't change selected row: stuck on first row

In short, my problem is that the WPF DataGrid won't let me select anything other than the first row. When I first fill it with data, no row is selected. Next, no matter what row I click on, the first row lights up. When I bind the SelectedItem property using OneWayToSource, I see that the correct row was indeed selected. If I choose to click again on a different row, nothing happens: the UI remains stuck on the first row and the SelectedItem property retains the previously correct value. At this point, I have to ctrl-click the first row to deselect things. This allows me to repeat the above situation.
In other words:
- the UI seems to be out of sync with what is actually selected.
- Ctrl-click is required to de-select the selection.
- Ctrl-click must be executed on the first row even if the SelectedItem property indicates that a different row is selected.
I understand this is bizarre behavior. I've tried to duplicate it in a separate project with no success. As such, I'm just throwing this out there to see if anyone has any ideas why it might be acting this way?
The only things that I have not duplicated in my separate project is the use of MEF for the View/ViewModel hookup. Everything else is the same.
EDIT: I just replaced said DataGrid with a ListBox and am experiencing the same problem. I'm using Snoop to try to figure out what might be applied to the control that would change its behavior so much.
My problem was that the objects that I was adding to the DataGrid and ListBox had overridden Equals() and GetHashCode() functions. These really screwed up the way both controls rendered which item was selected, therefore explaining the SelectedItem issue. In the end, all the problems were solved by simply removing/fixing those overrides.
Woot!

Categories

Resources