OnTextChanged even not working as expected in GridView - c#

I have a textbox in a gridview. The column template for the gridview binds data to the textbox. The original value will be called X. If I change the text in the textbox inside the grid view to Y the onTextChanged event will fire when I press a button. After I have changed the text to Y, and the event has fired, the event will continue to fire if each time i click the button. If I change the text to the orignal value, X, the onTextChanged event stops firing.
There are textboxes outside of the gridView. They all call onTextChanged as expected; When text is changed from what was there before.
How can I make the onTextChanged act like its expected instead of an onTextIsNotOrignalValue?

Have you tried to enable ViewState for the text box on the grid view? I am not sure if you have to enable Viewstate on the gridview itself.

Did you set AutoPostBack of Textbox to True?

Related

How to explicitly set a Control's Event order

I have a listbox which I have used as an autocomplete list in my C# windows application, which has events like MouseClick and Leave.
On MouseClick, I want to set the selected value to a textbox.
On Leave, I want to hide the listbox
Now, the problem is, when I click on a value in listbox, the leave event is fired and listbox gets hidden without setting the value. If I unset the leave event, things work as expected.
NOTE: The purpose of Leave event is to only hide the listbox when some other control is clicked. The autocomplete textbox is implemented using this reference: WinForms | C# | AutoComplete in the Middle of a Textbox?

How to handle text changing in DataGridViewTextBoxColumn

I have a dataGridView that contain a DataGridViewTextBoxColumn and also a DataGridViewComboBoxColumn.
The comboBox is bound to a dataSource, but textBox is not.
I want that when the TextBox changed, the selectedValue of comboBox set to textBox text.
When i put this code in cellLeave handler of dataGridView, the selectedValue of comboBox not change! This is because this handler fires up before changing the value of textBox.
((DataGridViewComboBoxCell)DgvA.Rows[DgvA.SelectedRows[0].Index].Cells[1]).Value = DgvA.Rows[DgvA.SelectedRows[0].Index].Cells[0].Value;
Does someone know how to do this?
Thers is no default handler for datagridviewTextboxColumn textchanged. You have to implement the handler.
When you start editing a cell in a DataGridViewTextBoxColumn, it's not like you have a TextBox. You actually do have a TextBox. A TextBox (more specifically, a DataGridViewTextBoxEditingControl, which inherits TextBox) is created and embedded in the cell. That control can be accessed in the EditingControlShowing event handler. You can attach a method to the TextChanged event of that control, just like any other.
That said, the grid doesn't actually contain changes just because an editing control does. If the user presses the Escape key then the changes in the editing control are discarded and never pushed down to the grid. The grid doesn't contain changes until the CellValueChanged event is raised.
You can try this code in this link.
https://infynet.wordpress.com/2012/01/24/textbox-text-changed-event-on-datagridview-cell/
You could bind both columns to the same property if the combobox is no lookup combobox.
Otherwise you could use a viewmodel (see MVVM) you copy your data to and use for binding. In this viewmodel you would have 2 properties, one for the textbox and one for the (key value of the) combobox. The one for the Textbox will in its setter update the other which will fire an property changed event and update the combobox.

dropdown selectedindexchanged issue within modalpopup extender

I'm having a dropdown in a ModalPopupExtender. The dropdown values are updated dynamically.
The problem is While clicking on the button in modal popup...The dropdown values was refreshed. So I tried to take the selected value of dropdown within the sectedindexchanged event. But If I put breakpoint with this also the control is not coming.
Can anyone tell me the fix for this?
SelectedIndexChanged is event triggered when the selection is changed, not when you change the items in the dropDown. for that you may use DataSourceChanged if you change the dataSource property or other, or other events, depend on what your code do ( please share it).

Hold focus on textbox that do something in the textchanged event

I have a problem:
I handled textchanged event of a textbox. When the event fires I do something in the UI (like add a row in a listbox) and the textbox lost the KeyboardFocus.
How can I hold the KeyboardFocus on that textbox?
Thanks
Write the following
this.MyTextBox.Focus()
at the end of your handler.
or make your UIElement.Focusable = false. it should help.
You can set the focus back on the textbox in the code-behind where you handle the event using textBoxName.Focus();
Focus can be set in the XAML using
FocusManager.FocusedElement="{Binding ElementName=textBoxName}"
but if the focus is lost when you add a new element then you may need to use code-behind to reset it.

Generating event for button inside gridview

In my project I'm showing a gridview in which I'hv included a buttonfield...I want to download a file, when user clicks the button inside gridview whose path is stored in database
and the file is stored in localfile system...
thanks in advance.
You can use the RowCommand Event of a gridview to responde to a button click and perform an action.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx
You can use the RowCommand event of the GridView control. Make sure your button has setup the CommandName and CommandArgument. The CommandName will distinguish between different events handled by the GridView RowCommand event. And the CommandArgument will contain any value you need to send to the GridView RowCommand through the Button click event.

Categories