DataGridView not losing focus - c#

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.

Related

WPF Datagrid copies and pastes on click, why?

I have a wpf C#-project with a standard wpf datagrid that is populated from a data table. It is rebound to the table every time the source changes (since I sometime use the datagrid to display data from different source). I handle the SelectedCellsChanged event to highlight the selected column, and the CellEditEnding event to update the source table with any cell changes made by user.
Here´s the strange thing: when I double click a cell and then click another cell, the value from the double-clicked cell is pasted to the clicked cell. I don’t handle Cell double click at all, this behavior seems to be intrinsic to the datagrid, but I cannot google my way to any info.
I would like to either get rid of this behavior, or be able to catch it (my application records and repeats any action made by the user and the one-click copy paste is actually quite neat, if I could just catch and save the action).
Actually, it was my code that caused the problem. Problem is, the CellEditEnding event is raised when cell loses focus and I managed to update the cell being clicked with the edited value of the previous cell (the one that lost focus.)
I struggled to find a solution, since there is no cell-leave event. Finally solved it, not very pretty, like this:
string rrow = MyGrid.Items.IndexOf(MyGrid.CurrentItem);
if (!(e.Column.Header.ToString() == MyDataTable.Columns[selectedColumn].ColumnName && e.Row.GetIndex() == rrow))
return;

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.

c# combobox drop down click deletes everything in textbox

I have a windows program (.NET 4.5) that has a combobox with custom dropdown data. My autocomplete type is set to AppendSuggest, so that the customer can easily type in a name, press tab or enter, and then move on to the next box to fill in.
When the combobox loses focus (goes to another control), the program will parse the text in the textbox. If the name exists in the database, it will attach that person to this instance, otherwise it will create a new person with the name (properly cased) in the database.
Pressing tab allows the autocomplete box to fill in the remaining text and it successfully attaches it to the database. However, if the enter button is pressed or, more importantly, the customer tries to click on a user from the autocomplete drop down list, the textbox simply deletes all text in it and moves on to the next box with nothing in it.
I can't find out how to intercept the data that the user clicks. Ideally, I just want the user to click an item from the dropdown list and have it fill the text in, then parse that text and move on.
I have also checked my code and there is no where in the code that deletes the text from this combobox. It seems to be happening by itself behind the scenes.
Also, I am a somewhat advanced programmer in C#, and although I really haven't worked with autocomplete, I am baffled that I am stumped on something as simple as this.

WPF Prevent button from taking focus from any other control

I have an "On screen keypad" with some up/down/left/right/select buttons.
The select button is effectively a click and the arrow keys fire the associated up/down/left/right key.
The problem is that when selecting a combo box, I can't press the down/up buttons to navigate the items in the list. It is because the combo box auto closes when loosing focus. I can see similar problems happening with other controls, so I would like to see if there is a way to do the following.
For certain buttons (up/down/etc), when clicked, fire the click event, but don't take focus from w/e currently has the focus. This would allow the combox dropdown to stay open while pressing up/down to navigate through the items.
I have tried to set Focusable=False on the navigation buttons but the focus is still taken away from the combo box and the dropdown closes.
Any ideas/suggestions?
Thanks in advance
This isn't happening because of anything your Buttons are doing so changing their focus state won't make any difference. ComboBoxes close when you click anywhere outside of them, including empty space, non-interactive controls, other windows...

C# dropdownmenuitem clicked and listview editing

I have 2 questions concerning C#.
1) I have a dropdown menu with several items in them. They are clickable, but when I click one, the older clicked one stays selected. Click another and the 2 original ones stay selected, and so on. I don't want this. What I want is that when I click one of the dropdownitems, that one is that selected one and the others are not.
2) I have a listview items on a winform. I loaded some string elements into it from a file. Now what I want to do is to be able to edit those strings and even add strings, just by clicking on the rows in which the data goes.
I've checked google and MSDN for these problems, but nothing helps, so I turn here.
2) The ListView does not support that type of action. You can roll your own (pain in the #$$), or perhaps a DataGrid would be better suited to your purpose.
EDIT:
This link may help
This one too
For #1 I'm a little confused. If the DropDownStyle isn't set to simple something strange is occuring. It's not much but maybe you could try recreating the control.
For #2 the easiest solution I can think of is to set a TextBox to be equal to the selected text value from your listview. After that write a little function to update the selected index of the listview with the edited text from the listview.
Please comment if you have any more information about #1.

Categories

Resources