3 Replies - 7838 Views - Last Post: 10 May 2011 - 11:57 PM Rate Topic: -----

#1 yatin chauhan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-May 11

autocomplete functionality in text box using data from database

Posted 10 May 2011 - 12:03 AM

Hi,

I am using MS acess database 2007 and visula studio 2008.

i am working on a windows application where i need to use the autocomplete functionality in text box and it should take values from the data base.
this is the code i am using up for it
Private Sub TFreightType_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TFreightType.TextChanged 
    Dim conn1 As OleDbConnection

    Dim connection1 As String

    Dim command1 As String

    Dim cmd1 As OleDbCommand

 

    command1 = ("select distinct (Freight_Type) from Sheet1 ")

    connection1 = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\application spot pricing\Database31.accdb"

    conn1 = New OleDbConnection(connection1)

 

 

    Try

    conn1.Open()

    Catch ex1 As Exception

    MsgBox("Can not open connection ! ")

    End Try

    Try

    cmd1 = New OleDbCommand(command1, conn1)

    Dim dr1 As OleDbDataReader = cmd1.ExecuteReader()

    If dr1.HasRows = True Then

 

    While dr1.Read()

      namesCollection.Add(dr1("Freight_Type").ToString())

      Debug.Print(dr1("Freight_Type"))

    End While

    Else

    MessageBox.Show("Data not found")

      End If

    dr1.Close()

    Debug.Print(namesCollection.Item(0))

    

    TFreightType.AutoCompleteMode = AutoCompleteMode.Suggest

    TFreightType.AutoCompleteSource = AutoCompleteSource.CustomSource

      TFreightType.AutoCompleteCustomSource = namesCollection

 

    Catch ex As Exception

    MsgBox("problem with data")

    End Try



in debugging mode it is showing that it is picking the distinct values but the auto complete functionality is not getting reflected in the front end .
can any one help me with this?
thanks

This post has been edited by modi123_1: 10 May 2011 - 06:57 AM
Reason for edit:: please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: autocomplete functionality in text box using data from database

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: autocomplete functionality in text box using data from database

Posted 10 May 2011 - 07:38 AM

This code looks like it would work but I think your problem is with it being in the textchanged event. It will fire with each character typed and will not work with the first character typed. In other words if your list contained (Test1 and Test2 as options) typing T would not produce anything but deleting T and typing it again should show your list with both Test1 and Test2 in it.

My suggestion, move your code into the form_load or Form_Shown event and see if you get better results.

This post has been edited by CharlieMay: 10 May 2011 - 07:39 AM

Was This Post Helpful? 0
  • +
  • -

#3 yatin chauhan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-May 11

Re: autocomplete functionality in text box using data from database

Posted 10 May 2011 - 07:43 AM

View PostCharlieMay, on 10 May 2011 - 07:38 AM, said:

This code looks like it would work but I think your problem is with it being in the textchanged event. It will fire with each character typed and will not work with the first character typed. In other words if your list contained (Test1 and Test2 as options) typing T would not produce anything but deleting T and typing it again should show your list with both Test1 and Test2 in it.

My suggestion, move your code into the form_load or Form_Shown event and see if you get better results.



thank you for ur suggestion. i will try it that way...
Was This Post Helpful? 0
  • +
  • -

#4 yatin chauhan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-May 11

Re: autocomplete functionality in text box using data from database

Posted 10 May 2011 - 11:57 PM

that worked thanks...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1