WPF ComboBox TextChanged event overrides navigation - c#

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 :-)

Related

ComboBox Event works with ListBox but not with GridView

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".

How to fill a data to a text box when grid view is clicked

I have a grid view displaying search results.
Once a field is selected, the data should be displayed in text boxes.
What's the code to fill text boxes when a row of a data grid view is clicked?
I've tried the code that is shown below. It returns an error.
TextBox1.Text = GridView1.SelectedRow[0].Cell[1].Value.ToString();
Index of Currently Selected Row in DataGridView
There you have all you want.
Next time try to use google, or search on that site, before you ask.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview(v=vs.110).aspx
Gridview has lot of events associated with it. based on the location of the text boxes, you may want to use RowEditing event or SelectedIndexChanged event.

How to update DataGrid items automatically?

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

How do I check if a selected item has changed from the previously selected item?

I have a listbox in my winform, when an item in the listbox is selected, a value is placed into a textbox in the same Form. There my many items in my listbox which when selected, i want the text box to be empty so i can pass in the new value. How do i check is if the user has clicked on something other their initial selected item? i get the currently selected item like this below:
var selectedItem = (ReportItems)listbox.selectedItem
You can use the SelectedIndexChanged event on your ListBox . You can create an event handler for this event to determine when the selected index in the ListBox has been changed. This can be useful when you need to display information in other controls based on the current selection in the ListBox. You can use the event handler for this event to load the information in the other controls.
See MSDN documentation: link
You can add a global variable for your ReportItems and call it 'selItem'.
After the user changed the selected Item you check the "new" selectedItem with the 'selItem'-variable.. i don't think that a listbox has a method that can check if the selection has changed from the previous one..
I'm not sure if there is a reason you're not leveraging the SelectionChanged event of the ListBox or not but you should be if you're not. Further, determining if it's different than the initially selected item should be pretty straight forward because you can save the initially selected item in a private variable in your form and compare every time the method handler for SelectionChanged fires.
Other than this, there's not much more I can suggest because your questions isn't terribly clear and there is no code to look at.
My solution was to always clear the textbox first. So as soon as a user selects an item in the listview, rather than populating the textbox straight away, clear the textbox before populating it.
clearText(); is called soon as a listbox item is clicked.
public void clearText()
{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
textBox7.Clear();
textBox8.Clear();
textBox9.Clear();
textBox10.Clear();
textBox11.Clear();
textBox12.Clear();
}

How to narrow the options list in a comboBox by typing - incremental search

I have a combobox that has hundreds item in it. User must be able to type the text into the combobox. While the user is typing the text, the item that starting with the typed value must be selected or listed. The user must be able type continuously. My ComboBox DropDownStyle is DropDownList
E.g: While selecting a name in comboBox by typing, it only allows one letter. So if I type "A" it will jump to the first letter starting with "A". When I type continuously the combo box selected item changes according to the current keypress. If I press "As", combobox viewing the items starting with "s".
comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown;
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
You will have to hook up to the TextChanged event. When the text
changes, filter the list (using a DataView) and take the text of the first
result, setting the text of the combo box to that. You would have to have a
check in your handler of course, to determine whether or not to handle the
event (when you change the text, another TextChanged event would be fired).
Of course, you also want to highlight the text that they typed in, and
place the caret at the appropriate position.

Categories