|
|
the code works perfectly !! 
|
|
|
|
|
|
|
I'm new to VB.Net and I found it surprising that this kind of behavior was not built in the basic combobox control?!
So thank you very much for the code, I found it really helpful.
It works exactly as I wanted.
Zestelle
|
|
|
|
|
I am receiving problem like sysntax error in INSERT INTO statement. I checked it again n again but I am unable to find eror in this code segment if anyone can help i will appeciate their concern.
code segment is
cmd = New OleDbCommand("INSERT INTO Transaction VALUES('" & WithDrawTxt.Text & "','" & AccountNo.ToString & "','" & dt.ToString & "')", cn)
i = cmd.ExecuteNonQuery
Table INFO
Table Transaction has fields Amount, Account_Number, Transaction_Date and last is Transaction#. All have field text except Transaction# which is auto number.
|
|
|
|
|
MS Access rejects some non-alphanumeric characters like ' (apostrophe), if not formatted properly. Try this: cmd = New OleDbCommand("INSERT INTO Transaction VALUES('" & WithDrawTxt.Text.Replace("'","''") & "', '" & AccountNo.ToString & "', '" & dt.ToString & "')", cn). Also, for inserting numbers into MS Access Database, you may find it easier if you set the "AccountNo" field in the database to "Number", instead of "Text". This way, you can remove the ' (apostrophes) surrounding your number in the sql string ('" & AccountNo.ToString & "','"). If you do change the MS Access field type to "Number", the sql string should look like this: cmd = New OleDbCommand("INSERT INTO Transaction VALUES('" & WithDrawTxt.Text.Replace("'","''") & "', " & AccountNo & ", '" & dt.ToString & "')", cn).
One last observation; I don't know what format "dt" is in, but if you have the MS Access field set to "DateTime", and you are attempting to send it a string value (dt.ToString)(if dt is a date in string format), then that will fail every time. If dt.ToString is in some type of "date/datetime" format, you have to enclose the value with the # (pound sign), like this: ...,'" & AccountNo.ToString & "', #" & dt.ToString & "#)", cn)
Hope this helps.
b.ware,
A.P.W.S (A programmer without sleep)
b.ware,
A.P.W.S (A programmer without sleep)
|
|
|
|
|
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
|
|
|
|
|
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;
[$@^^€€]
|
|
|
|
|
sorry there that feature works in 2.0
[$@^^€€]
|
|
|
|
|
Its works for me. thank you soooooo much.
Im a fairly novice programmer and I dont know how to state what Im looking for. I ran into the original post. Saw all the code he had to go through and decided to see if someone had modified it any when I ran into your post.
Works like a charm. Only the page flutters a couple time after you select a record. Any idea why ?
Mike Dibble
|
|
|
|
|
i find the code very helpful for a beginner like me....thanks
more power
knowlege is a treasure but practice is the key
|
|
|
|
|
knowlege is a treasure but practice is the key
|
|
|
|
|
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 ????
|
|
|
|
|
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
|
|
|
|
|
I've ran into problems when I tried to type in more than one character for the autocomplete.
My solution was to add this code to the Leave event of the combo box:
Me.SelectionStart = 0
Me.SelectionLength = Me.Text.Length - Me.SelectionStart
That fixed the 'SelectedText' property, but for some reason when the LostFocus method fires the selected index gets reset, even though the text of the combo box is still correct. To fix this I added the following code to the LostFocus event of the combo box:
Me.SelectedIndex = Me.FindStringExact(Me.Text)
Hope this helps.
-S
|
|
|
|
|
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;
}
|
|
|
|
|
* Private Sub comboBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
* _lastKey = e.KeyCode
* End Sub
*
* Private Sub comboBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
* Dim cbo As ComboBox = DirectCast(sender, ComboBox)
* Dim srch As String = cbo.Text
*
* If _lastKey = Keys.Back OrElse _lastKey = Keys.Delete OrElse _lastKey = Keys.None Then
* _lastKey = Keys.None
* Exit Sub
* End If
* _lastKey = Keys.None
* Dim idx As Integer = cbo.FindString(srch)
* If idx <> -1 Then
* cbo.SelectedIndex = idx
* cbo.SelectionStart = srch.Length
* cbo.SelectionLength = cbo.Text.Length - srch.Length
* End If
* End Sub
*
* Private Sub comboBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs)
* Dim cbo As ComboBox = DirectCast(sender, ComboBox)
* cbo.SelectedIndex = cbo.FindStringExact(cbo.Text)
* If cbo.SelectedIndex = -1 Then
* cbo.Text = String.Empty
* End If
* _lastKey = Keys.None
* End Sub
b.ware
|
|
|
|
|
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
|
|
|
|
|
I don't see a reference for DB in this example!
|
|
|
|
|
Did you get a reply to this or were you able or figure it out?
I'm trying to replicate this in C#.
|
|
|
|
|
nice attempt but needs improvement
9891965160
developer.nettechnologies@gmail.com
|
|
|
|
|
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. 
|
|
|
|
|
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
|
|
|
|
|
This works great. Thanks
Tunca Bergmen
|
|
|
|