Auto suggest and display corresponding details of id entered
Hi guys :wave:
I have previously asked a questions regarding DataGridView control: http://www.vbforums.com/showthread.php?t=661859
Now I'm trying to make the first column to include an autosuggestion. ie. when a user types an ID(say, "12") then all the records that starts with it(ie. "12*") will be displayed as suggestion.
And upon clicking an ID, the corresponding product_name will be displayed on the next column. I think, I could do this using Validating() event of DataGridView.
But how would I add the autosuggestion for the first column ?
Thanks :wave:
Re: Auto suggest and display corresponding details of id entered
Found this thread: http://www.vbforums.com/showthread.php?t=590762
And converted the code using Telerik Code Converter:
vb.net Code:
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
Dim Role As String = e.Control.AccessibilityObject.Role.ToString()
Select Case Role
Case "ComboBox"
Dim cbo As ComboBox = TryCast(e.Control, ComboBox)
Exit Select
Case "Text"
If Me.DataGridView1.CurrentCell.ColumnIndex = 0 Then
Dim txt As TextBox = TryCast(e.Control, TextBox)
If txt IsNot Nothing Then
If _ModuleAutoCompleteSuggestion IsNot Nothing Then
Array.Sort(_ModuleAutoCompleteSuggestion)
txt.AutoCompleteCustomSource.Clear()
txt.AutoCompleteCustomSource.AddRange(_ModuleAutoCompleteSuggestion)
txt.AutoCompleteSource = AutoCompleteSource.CustomSource
txt.AutoCompleteMode = AutoCompleteMode.Suggest
End If
End If
End If
Exit Select
End Select
End Sub
It's showing an error on the AccessibilityObject line:
Code:
Error 1 Reference required to assembly 'Accessibility, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' containing the implemented interface 'Accessibility.IAccessible'. Add one to your project.
Any ideas ?
Thanks :wave:
Re: Auto suggest and display corresponding details of id entered
add this file as a reference.....
"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Accessibility.dll"
Re: Auto suggest and display corresponding details of id entered
Added reference to the Accessibility and that error is resolved.
Code tested:
vb.net Code:
'~~~ Class level declaration
Dim AutoCompleteSuggestions() As String = {"1211", "123", "215", "1256", "123354"}
'...
'.....
'......
'~~~ AutoSuggestion
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
Dim Role As String = e.Control.AccessibilityObject.Role.ToString()
Select Case Role
Case "ComboBox"
Dim cbo As ComboBox = TryCast(e.Control, ComboBox)
Exit Select
Case "Text"
If Me.DataGridView1.CurrentCell.ColumnIndex = 0 Then
Dim txt As TextBox = TryCast(e.Control, TextBox)
If txt IsNot Nothing Then
If AutoCompleteSuggestions IsNot Nothing Then
Array.Sort(AutoCompleteSuggestions)
txt.AutoCompleteCustomSource.Clear()
txt.AutoCompleteCustomSource.AddRange(AutoCompleteSuggestions)
txt.AutoCompleteSource = AutoCompleteSource.CustomSource
txt.AutoCompleteMode = AutoCompleteMode.Suggest
End If
End If
End If
Exit Select
End Select
End Sub
:wave:
Re: Auto suggest and display corresponding details of id entered
Quote:
Originally Posted by
medsont
add this file as a reference.....
"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Accessibility.dll"
Thanks :wave:
Already figured it out. :)
Now, the suggestions combobox is showing. But upon selecting an item from it(double clicking) it just add to the first column and moves to the next record. Which was supposed to be moved onto the next column. But when pressing the tab button(while an item from the combobox is selected - single click) will save the selected item in first column and move onto the next column.
Any ideas on how to resolve it ? :confused:
:wave:
Re: Auto suggest and display corresponding details of id entered
Another question:
I didn't got the idea of this line:
Code:
Dim Role As String = e.Control.AccessibilityObject.Role.ToString()
Can anyone tell me what it does ? :confused:
Thanks :wave:
Re: Auto suggest and display corresponding details of id entered
Re: Auto suggest and display corresponding details of id entered
Quote:
Originally Posted by http://msdn.microsoft.com/en-us/library/system.windows.forms.accessibleobject(v=VS.71).aspx
Provides information that accessibility applications use to adjust an application's UI for users with impairments.
:confused: