 |
|
|
I seem to be (as usual) confused by the behaviour of autocomplete combos. Is it my imagination or do autocomplete combos change their selected indexes when they are selected? I have an app where this seems to be happening... a little background...
On a winform I have three combos all populated from the same arraylist.A concept number, an item number and a name, all related and associated. there are occasions when, for instance, I have set the selectedindex to, say 122, via selecting a concept number, and when I click or tab to the next combo, the selected indexes seem to be set to 0! Very irritating. This is definately in some way due to autocomplete, because if I make them all autocomplete false this doesn't happen. Unfortunately there is a reqirement for autocomplete.... I'm really frustrated and all my googling has not yet gotten me an solution!
Michael S. Comperchio michael.comperchio@hotmail.com 203 218 4053
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
please try following properties to enable autocomplete feature for combo box... set theese properties form property window... cb.AutoCompleteSource=ListItems //there are other options also... cb.AutoCompleteMode=SuggestAppend //there are differnets modes available u can try them also....
for code try this.... this.cb.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend; this.cb.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
[$@^^€€]
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
i find the code very helpful for a beginner like me....thanks
more power
knowlege is a treasure but practice is the key
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
If you use DroppedDown=true to make the combo behave like an IE autocomplete combobox the combox shows the selected text but when you try to get it through code for ex: combobox.Text or combobox.SelectedIndex point to the previous selection.
Any one figure out how to get around this issue ????
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I have the same problem and can't pin down where its going wrong. Until yesterday i thought my users were going mad reporting very intermittent problems, I wont say anything about my testing...
Seems to me that the updated value is definitely being saved but then overriden with the old value somewhere, eg as soon as we enter the leave event the old value is back. I've had a look through the events and properties but cant see anything you need to set to persist the value, eg like the way you handle the key events.
In the end I've had to resort to using a temporary form level object to store the autocomplete value of the combobox and a flag to indicate whether our autocomplete code has been used. in the leave event if flag == true point the combobox to the temporary object and reset the flag to false. I really dont like to do this as its a very bad solution so if anyone has a proper way i'd love to know.
paulmcl
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
After looking at your code, and then looking at some of my old Delphi code. I found that the following code worked a little better for me.
Just thought I would share 
(Sorry about the C# code)
private void comboBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { _lastKey = e.KeyCode; }
private void comboBox1_TextChanged(object sender, System.EventArgs e) { ComboBox cbo = (ComboBox) sender; string srch = cbo.Text; if (_lastKey == Keys.Back || _lastKey == Keys.Delete || _lastKey == Keys.None) { _lastKey = Keys.None; return; } _lastKey = Keys.None; int idx = cbo.FindString(@srch); if (idx != -1) { cbo.SelectedIndex = idx; cbo.SelectionStart = srch.Length; cbo.SelectionLength = cbo.Text.Length - srch.Length; } }
private void comboBox1_Leave(object sender, System.EventArgs e) { ComboBox cbo = (ComboBox) sender; cbo.SelectedIndex = cbo.FindStringExact(cbo.Text); if (cbo.SelectedIndex == -1) cbo.Text = string.Empty; _lastKey = Keys.None; }
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
Hi mfs ... I saw this code few days ago and i use it, i also read the mesages all of u post to see how it works. My problem ocurred when i wrote quickly.
I put the class that inherit the combobox taht one of u post but it didn't solve my problem. i can write fast and it capture all the characters i want, but when i wrote the first character that change the word and it isnt in my combo the cursor pass to the last position (max length) and i continue writting there, so it leave a lot of blank spaces, but if i type slowly it doesnt happend, i can continue typing after the last char.
I hope u undertood my question and can solve ir .. thx
Pd .. sry 4 my english
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
 |
|
|
The above code is great, for slow typers. I found that when I type quickly in the combo box, it doesn't find the correct entry. When I type the same thing slowly, everything works fine.
any ideas on how to get around this problem? I've looked at various alorithms (mostly very similar variants) for autofill and it seems that all would have this problem. Never had this problem on custom autofill routines on data bound controls in Vb6.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I've had this problem in the past as well. I found that the problem would be when a 2nd (or 3rd, 4th, etc.) key was pressed before the first key was released. This wouldn't be an issue for someone with only one finger, but for the rest of us my solution is as follows.
Declaration of my control:
Public Class AutoFillComboBox Inherits ComboBox
First add a private data member to store the most recent keydown key:
Private _LastKeyDown As System.Windows.Forms.KeyEventArgs
In the KeyDown event of my object, I'll store the key that was pressed:
Protected Overrides Sub OnKeyDown(ByVal e as System.Windows.Forms.KeyEventArgs) MyBase.OnKeyDown(e) _LastKeyDown = e End Sub
And finally, the first thing I do in the KeyUp event is to ensure that the key that was released was actually the last key pressed (ie: ignore the KeyUp unless it was also the last KeyDown). Also, a key may have been held down before the control was loaded, so if the last KeyDown doesn't exist (Is Nothing), ignore that too:
Protected Overrides Sub OnKeyUp(ByVal e as System.Windows.Forms.KeyEventArgs) MyBase.OnKeyUp(e) If (_LastKeyDown Is Nothing) = True OrElse (e.KeyCode = _LastKeyDown.KeyCode) = False Then Exit Sub ....... processing to AutoComplete ....... End Sub
I'm sure that using overrides is unnecessary, and you could probably just store the e.KeyCode value in a System.Windows.Forms.Keys variable, but that's not the point. Hope this helps someone out there in the future...
Joseph Hicks jhicks<AT>ifmc.org
|
| Sign In·View Thread·PermaLink | 5.00/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
 |
|
|
Can anybody suggest and easy and efficent way to save the contents of the combobox and when a form is reloaded, The data brought back in to the combobox.
I have tried to use this code, and it works great. But I am having difficulty saving all the data and reloading it.
Any help appreciated.
Thanks
Chris
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
|
1- databases (mysql, msqls, etc) -> if you are working with large amounts of complex data... 2- XML -> save/load to/from a xml file. 3- ini -> save/load to/from a ini file. if you want more info about these files, search in this same site.
|
| Sign In·View Thread·PermaLink | 2.00/5 (3 votes) |
|
|
|
 |
|
|
 |
 | Escape |  | Anonymous | 18:48 15 Oct '03 |
|
|
I created a new combobox control based on the codes. But why it seems when the combobox item list is currently dropdown, as i key in the characters, when I press key, and leave the combobox, the text remain as it is but the actual index is actually at the previously selected item. The key also seems to have the same kind of observation. How to solve it?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
If Char.IsControl(e.KeyChar) Then Return
With Me.ComboBox1
Dim ToFind As String = .Text.Substring(0, .SelectionStart) & e.KeyChar Dim Index As Integer = .FindStringExact(ToFind)
If Index = -1 Then Index = .FindString(ToFind) If Index = -1 Then Return
.SelectedIndex = Index .SelectionStart = ToFind.Length .SelectionLength = .Text.Length - .SelectionStart
e.Handled = True
End With End Sub
|
| Sign In·View Thread·PermaLink | 4.86/5 (6 votes) |
|
|
|
 |
|
|
 |
|
|
 |
|
|
All the more so because the original example does strange things when you tab into the control. It isn't anything that is hard to handle, and the code still works, but if you are designing to the lowest common user denominator, you want things to behave like they typically do in other windows programs. I found autocomplete code for vb.net on msdn once, but since I forgot to save the link/code I'm sure glad I found you guys. Thanks for the code!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
add this
Me.ComboBox1.DropDown = True; If Char.IsControl(e.KeyChar) Then Return
It will work like that address bar in IE.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |