 |
|
 |
i have been trying to convert this sample to VB but have not been having some problems.
do you have a VB version, or can you provide one?
the dependency property for the PatternChanged doesnt seem to be defined in a way that i have been able to convert it.
also i cant seem to convert this so that the designer will even allow it:
this.Dispatcher.BeginInvoke((Action)delegate
{
this.IsDropDownOpen = true;
// load from event source
if (this.PatternChanged != null)
{
AutoCompleteArgs args = new AutoCompleteArgs(this.Text);
this.PatternChanged(this, args);
// bind the new datasource if user did not cancel
if (!args.CancelBinding)
{
this.ItemsSource = args.DataSource;
if (!this.TypeAhead)
{
// override auto complete behavior
this.Text = args.Pattern;
this.EditableTextBox.CaretIndex = args.Pattern.Length;
}
}
}
},
System.Windows.Threading.DispatcherPriority.ApplicationIdle);
'Me.Dispatcher.BeginInvoke((Action)Sub()
' ' load from event source
' ' bind the new datasource if user did not cancel
' ' override auto complete behavior
' Me.IsDropDownOpen = True
' If Me.PatternChanged IsNot Nothing Then
' Dim args As New AutoCompleteArgs(Me.Text)
' Me.PatternChanged(Me, args)
' If Not args.CancelBinding Then
' Me.ItemsSource = args.DataSource
' If Not Me.TypeAhead Then
' Me.Text = args.Pattern
' Me.EditableTextBox.CaretIndex = args.Pattern.Length
' End If
' End If
' End If
'End Sub, System.Windows.Threading.DispatcherPriority.ApplicationIdle)
chj...
|
|
|
|
 |
|
 |
There's a bug. If you set the dropdown visible by clicking it and type text for autocomplete, then click other than auto selected item, it does not select the clicked one.
|
|
|
|
 |
|
 |
hi i dont realy understand this
|
|
|
|
 |
|
 |
No disrispect but Hanan's solution works much better! Go for that if you need this type of functionality...
www.leoseccia.co.uk
Leo
|
|
|
|
 |
|
 |
How do I add this control at design time?
|
|
|
|
 |
|
 |
Seems working really great. Thx a lot!!!
|
|
|
|
 |
|
 |
this solution is translated form Laurent Muller's comment in VB,
found at http://codeproject.com/vb/net/autocomplete_combobox.asp#xx740929xx
Add this to a class derivative from ComboBox:
protected override void OnKeyPress(KeyPressEventArgs e)
{
// handels autocompletion for dropduwn mode
base.OnKeyPress (e);
if (Char.IsControl(e.KeyChar))
return;
String ToFind = this.Text.Substring(0, this.SelectionStart) + e.KeyChar;
int index = this.FindStringExact(ToFind);
if (index == -1 )
index = this.FindString(ToFind);
if (index == -1 )
return;
this.SelectedIndex = index;
this.SelectionStart = ToFind.Length;
this.SelectionLength = this.Text.Length - this.SelectionStart;
e.Handled = true;
}
Or Add to the form containing the comboBox:
private void ComboBox1_KeyPress(Object sender,System.Windows.Forms.KeyPressEventArgs e)
{
ComboBox cb = (ComboBox)sender;//this.ComboBox1
if (Char.IsControl(e.KeyChar))
return;
String ToFind = cb.Text.Substring(0, cb.SelectionStart) + e.KeyChar;
int index = cb.FindStringExact(ToFind);
if (index == -1 )
index = cb.FindString(ToFind);
if (index == -1 )
return;
cb.SelectedIndex = index;
cb.SelectionStart = ToFind.Length;
cb.SelectionLength = cb.Text.Length - cb.SelectionStart;
e.Handled = true;
}
|
|
|
|
 |
|
 |
Please explain to me how this is any simpler or any more elegant than the approach I took.
The algorithm is the same; the only difference appears to be what event you trap, and based on the event you trap, you are having to break out of the method conditionally, if they hit an incorrect key.
--
Matt Berther
http://www.mattberther.com
|
|
|
|
 |
|
 |
Matt Berther wrote:
Please explain to me how this is any simpler or any more elegant than the approach I took.
Well for one his approach works, and yours does not. His approach begins autocomplete when the first character is typed, your approach requires at least two characters before autocomplete begins.
Strange behavior... I have discovered with your solution (sometimes) when you tab into the box and start typing, the first character is inserted to the right of the cursor, killing the autocomplete, and requiring you to backspace and begin typing again before autocomplete kicks in. Looking through your code, I have no idea why this is happening, but I do know the alternative approach posted here does not behave that way.
|
|
|
|
 |
|
 |
Well for one his approach works, and yours does not. His approach begins autocomplete when the first character is typed, your approach requires at least two characters before autocomplete begins.
Works on the first character for me. Also have not had any issues when tabbing into the box.
Works like a treat...
|
|
|
|
 |
|
 |
Hello
I'm new to C# I'm looking a lot for such control but for my point of view none of your method are explicit nor very documented no good explain how to use them
So it is totaly unusable for me as it is
I'is maybe easy for expert but expert probably do not need such code.
I'm still looking for a good documented code for auto complete combo box
AND the way to use it !!
|
|
|
|
 |
|
 |
Very useful code - thanks!
I found that it would only start the auto search on the second character, which I fixed by putting the code into the OnKeyUp event instead of the OnKeyDown event. It seems the Text property doesn't get updated with the text that has just been typed until you let go of the key!
Cheers,
ASN
|
|
|
|
 |
|
 |
This control seems to work. The problem I have found is the scroll bar does work with the mouse.
|
|
|
|
 |
|
 |
I found an error behavior of combobox. When a combobox is placed in tabControl and I set the SelectedIndex to -1 indicating that the user has not made his choice yet, When the tabControl switch to other page and switch back to the page with the comboBox. The SelectedIndex will become 0 and no events of text-changed or selected-index-changed fired that caused my validating logic failed.
Do you know how to get around this problem?
|
|
|
|
 |
|
 |
I have noticed this error too.
but this does not point to problem of the custom control...
this issue seems like bug in .net framework.
solved with extra state maintanance...
--
(:name "Valdis Iljuconoks"
:office "RIX Technologies"
:position "system analyst"
:gsm "+371 9198281")
|
|
|
|
 |
|
|
 |
|
|
 |
|
 |
I've noticed that tab controls in .NET arent as mature as they should be. It would appear as if the tab control is not receiving the BindingContext from its parent properly.
Glad to hear that it worked for you.
--
Matt Berther
http://www.mattberther.com
|
|
|
|
 |
|
 |
However, it works only if the combobox is in the first tabpage.
If the combobox is in the second tabpage, the same problem happened again.
|
|
|
|
 |
|
 |
Donny,
You are setting the bindingcontext for each tab *page*, not just the tab control, correct?
--
Matt Berther
http://www.mattberther.com
|
|
|
|
 |
|
 |
According to this article[^] at MSDN, this is expected behaviour, as the TabControl fires OnBindingContextChanged when the tab page is switched.
The solution is fairly simple, although I havent tested this in a broad scope. I did test against the sample you sent me with favorable results.
Derive a new class from ComboBox and override your OnBindingContextChanged() method with a blank implementation.
This works, because System.Windows.Forms.ListControl resets the data connection in its implementation of OnBindingContextChanged().
Example:
class TabPageComboBox : System.Windows.Forms.ComboBox
{
protected override void OnBindingContextChanged(EventArgs e)
{
}
}
Above is the simplest implementation, however, you may be able to something like:
class TabPageComboBox : System.Windows.Forms.ComboBox
{
protected override void OnBindingContextChanged(EventArgs e)
{
if (this.SelectedIndex != -1)
{
base.OnBindingContextChanged(e);
}
}
}
I misunderstood your original problem, and with these solutions, you will not need the tabPage.BindingContext = blah blah lines.
This will reset the data connection if an item has been selected.
--
Matt Berther
http://www.mattberther.com
|
|
|
|
 |
|
 |
I got other problem about the combobox. I have around six comboboxes in a form with the datasources refering to different dataviews that point to the same datatable "customer".
Initially, I set the comboboxes as blank. (i.e. the selectedindex=-1 )
When a user cannot find any item in the combobox, he invokes a form to add the new item and expects to be reflected in the selectable items of the comboboxes. However, after a new record was added in the datatable, all six comboboxes are set to the first item. (i.e. the selectedindex=0 )
I checked all the binding-related events of the combobox but none of them are fired due to adding new records in the datatable of the dataviews.
Do anyone have the hints to avoid it??
Thanks.
|
|
|
|
 |
|
 |
I also found this error and my solution is as below and found that it work;
-use this.tabPage1.BindingContext = this.BindingContext; as advised by author, comboBox.Text value change error has been solved, But still got comboBox.Text value be changed while click botton save inwhich is outside tabControl. so, have to add EditText = Text; to save the current edit text in the protected override void OnValidating(System.ComponentModel.CancelEventArgs e) , and change your code that get comboBox.Text to dataset to be comboBox.EditText instead. Hope this may help anyway.
|
|
|
|
 |
|
 |
When datasource is set, auto complemete combo box does not return a valid selecteditem, and selectedindex is always -1.
|
|
|
|
 |
|
 |
event after combobox loses its focus ?
i had no problems with this control and used it with enjoy in my application.
|
|
|
|
 |