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
Related
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".
i have a bound dataGridView where i load a list of objects using a bindinglist.
Each row has a datagridviewcomboboxCell and a textcell. The comboboxes are filled with enum values.
Depending on the item selected in the combobox the textcell should have another cellStyle. E.g. if the user selects the first item of the combobox, the cell should be green, if he selects the second item, the cell should be blue, and so on...
I implemented Handlers on the dataGridviewComboboxCell when the user adds a new row to the dataGridView. This works perfect using DataGridView.EditingControlShowing event.
But if i bind a list containing objects to the datagridview, the EditingControlShowing event is not fired. So i need to know how i can add the eventhandlers to the datagridviewComboboxCells when the data is loading into the dataGridView (using datasource).
I figured out, that i can use the DataSourceChanged event getting all data, but i can not access the cells control to add a handler.
As JayV posted: I can use CellFormatting on loading the data. If the user change the item in the combobox, then the handler is added to the combobox and it works as it should.
I have a DevExpress WPF datagrid and the SelectedItem is used via Binding in the ViewModel.
When I select a row, it loads data in a detail view.
However, when I select a filter cell, it also triggers the SelectedItem binding and it tries to load...well, nothing as there is no real row selected.
I intend to use the filter as the following: the SelectedItem is the first item in the filtered list.
How can I prevent the filter cell from triggering the SelectedItem change and make my first item as the selected one?
You need to set the SelectedItem's Binding with an
UpdateSourceTrigger=PropertyChanged
the default UpdateSourceTrigger for all binding's inside a DataGrid is LostFocus.
that's why your item is updated when leaving the row , it lost it's focus.
Please check syntax since it was not written in VisualStudio .
<ComboBox SelectedItem="{Binding YourItem,UpdateSourceTrigger=PropertyChanged}" />
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 am using a winform datagridview bound to a list. There is a checkbox column bound to a Boolean type field. The problem is, when check/uncheck a checkbox, its not updating the underlying list until I change focus to another cell of the datagrid view.
Is there any way to do it by not changing focus to another cell?