The function should be simple:
I select an item, which is added to a list, then i manage that item using the list.
As first try i put some buttons next to the listbox and it worked fine.
But the objective is to add two buttons in each row, so i replaced the listbox with a gridview.
What's the problem? The event SelectedIndexChanged of the ComboBox (which is used to add the item to the list) does trigger once but not the second time.
The page correctly goes through page load, but the combobox's event is ignored.
Code here:
https://pastebin.com/Bmg2qjTf
I think i must say the combobox is filled using an SQL: the first time the SQL Query is executed and applied to the ComboBox's DataSource and in a Session, on PostBacks instead it gets refilled thru the Session variable.
Solution: Adding a txtNumSpedizione.Text = "";
Troubleshooting:
I tried to make both (listbox and gridview) work at the same time and this way it worked, also the gridview was getting all the selections.
So i figured out the difference between before and after was in the Text field "reset".
Related
I'm using ComboBox for searching in database.
Event in XAML: TextBoxBase.TextChanged="text_changed"
Event in C#: text_changed retrive data into DataTable thru SQL query and populates collection of combobox items thru ItemsSource property.
Now, when i typing or pasting text into my combobox (if matches founds)
combobox shows DropDown list.
First problem is that i'm trying navigate to them by using keyboard arrow buttons, but TextChanged event fires again and fist item will be chosen.
Second problem is that when i erase incorrect typed symbol by backspace and database match increases, in this moment all of my typed text markup as selected..
Thanks for attention :-)
I have a weird problem with ComboBox Column in DataGridView in WinForm.
When I select the item from ComboBox, the selected value would not be rendered by the ComboBox. I need to click the ComboBox so that the selected value of the ComboBox would be rendered or displayed. If not, the ComboBox would just display empty.
The weird thing is this only happen in my first ComboBox Column in DataGridView.
In other words, this issue is not happening with my Second, Third or etc ComboBox Column in DataGridView.
Any ideas? Could it be a DataGridView bugs?
Thanks for your attention.
Thanks for your attention.
I manage to find the solution for the question that I have asked.
Overview:
I populate rows in DataGridView manually by adding row into DataGridView.
For DataGridViewComboBoxCell object, I use DataSource to populate the Items instead of adding the Items manually to the
ComboBoxCell.
The Problem:
Whenever you select the item in ComboBox, it is unable to render the selected value in the ComboBox. It would only show the value if you click it.
Solution:
It turns out in the code somewhere after I set the DataSource of the DataGridViewComboBoxCell, I called its method, DataGridViewComboBoxCell.Items.Count. This is the source of the weird behaviour.
Somehow, if you have set the ComboBoxCell DataSource, and you call Items.Count method, it would show that weird behaviour.
I should not use Items.Count since I am using DataSource. The Items.Count would always be zero because the DataBinding it's not happened instantly the moment you set the DataSource.
Hopefully this post would help someone else in the future. Thanks.
I have a DataGrid whose items can be edited by external ComboBoxes and TextBoxes (that is, the DataGrid SelectedItem is binded whith the same object as ComboBoxes and TextBoxes).
When I edit an Item in the external TextBlock the DataGrid selected item updates automatically. However when I edit an Item using the external comboboxes the DataGrid doesn't update.
I tried using the following methods when SelectionChanged event is triggered, but it didn't work.
MyDataGrid.CommitEdit();
MyDataGrid.CancelEdit();
MyDataGrid.Items.Refresh();
Any idea?
try to use the textbox events to trigger it, when the data is edited by them it will put it back in its place. or use a buttom
I am using a SelectedIndexChanged function for a combobox to update the content of my DataGridview item. I have the combobox data bound to keep track of it's currently selected record. However, when I changed the combobox index it updates the datagridview as if the selected value was the same. This means once I have selected a different index value in the combobox, I have to select it again to run the function with the proper value.
Am I missing something here? Do I need to call the check for the current datarow selected in the combobox before calling the SelectedIndexChanged function?
Sounds like the page life cycle issue, as the datagrid will be fired before the slected index change if its in the page load event. at which point the index wont have changed so the data will be the same.
I have a typical requirement.
I have a datagridview with a combobox column(items loaded at design time). When a user selects an item from combobox, remaining rows gets updated in database based on the selectedItem and dgv gets refreshed.
Problem is the combo box will lose its current selection and goes to unselected state.
I want to retain the selected item even after dgv refreshed.
Could anyone help me out
Thanks in advance
Do you mean that you're using an unbound comboboxcolumn? If so, the value can't automatically be persisted when refreshing the datasource. You need to store the selected value before updating and setting it in code after refresh.
If your column is actually databound, the selected value is either not stored in the database or you have some data type problem.
Is the combobox there to let the user select a value for the field or do you use it as a way to execute a command on the record?
Do you have any code you can post?
Datagrid Combo-Box value will retain the string value but will refresh any integer values automatically.
Here is what you need to do :
-When populating Combo-Box value to just convert its value to toString().
-Also if you are setting a default select value also set it with string type.
-Your Combo-box will automatically retain the value selected even after refreshing.
:)
have a combobox in ur datagridview. Assign values to it using a bindingsource.
then write an eventhandler for the datagridviews "EditingControlShowing" event.
in that, remove had handler if any exists for the comboboxes Selectedindexchanged event. then add an event handler for the selectedIndexChanged event say "ComboBoxValueChanged"
in that "ComboBoxValueChanged",
DirectCast the sender to System.Windows.Forms.DataGridViewComboBoxEditingControl and get the selected value of it.
Now use it to compute any value you want.
you may wana refer to this
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxeditingcontrol.aspx