C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » DataGridView »

Auto Complete For a TextBox Control in DataGridView


Posted Date: 29 Jun 2009    Resource Type: Code Snippets    Category: DataGridView
Author: PraveenMember Level: Diamond    
Rating: 1 out of 5Points: 7



Hi,

A Small Article Which Show you how to Show Tool tip for a Column Index of 1 in DataGridView

Before Going To the Main Function(s) we need to do some Small Manipulations to GridView
1. Grid View should have Enable Editing to True
2. Grid View Should have EditControlShowing Event

After doing that through Design now comes to code part

Declare a Variable Gobally


Private scAutoComplete As New AutoCompleteStringCollection



in Form_Load Event am Calling a Function Called bind Grid and let's have a look how bind Grid Function


Private Sub bindGrid()
DataGridView1.DataSource = getTable() ' To get Data Table for the Grid View
setAutoComplete()
End Sub

Private Sub setAutoComplete()
For i As Integer = 1 To 5
scAutoComplete.Add("Praveen " & CStr(i)) ' For Sample i added my name here you can load values from database
Next
End Sub



so in Form Load we binded data to Grid View and We gave values to Auto Complete Extender also

Now see the Code for Gridview Editing Controls Showing

Private Sub DataGridView1_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
If DataGridView1.CurrentCell.ColumnIndex = 1 AndAlso TypeOf e.Control Is TextBox Then ' Checking Whether the Editing Control Column Index is 1 or not if 1 Then Enabling Auto Complete Extender
With DirectCast(e.Control, TextBox)
.AutoCompleteCustomSource = scAutoComplete
.AutoCompleteMode = AutoCompleteMode.SuggestAppend
.AutoCompleteSource = AutoCompleteSource.CustomSource
End With
Else ' we are not Enabling Auto Complete Extendar
With DirectCast(e.Control, TextBox)
.AutoCompleteMode = AutoCompleteMode.None
End With
End If
End Sub


if you want to show for more than a column then take another AutoCompleteStringCollection Variable and assign to that autocompletecustomsource

hope this will help some one

Attachments

  • AutoCompleteTextboxinDataGridView (29740-291138-AutoComplete.zip)


  • Responses


    No responses found. Be the first to respond and make money from revenue sharing program.

    Feedbacks      
    Popular Tags   What are tags ?   Search Tags  
    Sign In to add tags.
    Show Tool tip in DataGridview  .  Auto Complete for a Textbox in DataGridView  .  

    Post Feedback


    This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
    You must Sign In to post a response.
    Next Resource: Creating Context Menu for Data Grid
    Previous Resource: DataGridView Checkbox Column Handling in VB.NET
    Return to Discussion Resource Index
    Post New Resource
    Category: DataGridView


    Post resources and earn money!
     
    More Resources



    dotNet Slackers

    About Us    Contact Us    Privacy Policy    Terms Of Use