Results 1 to 14 of 14

Thread: [RESOLVED] how to set the Textbox autocomplete source to specific column in my datatable

  1. #1

    Thread Starter
    Hyperactive Member snakeman's Avatar
    Join Date
    Aug 2006
    Posts
    351

    Resolved [RESOLVED] how to set the Textbox autocomplete source to specific column in my datatable

    hey guys
    how to set the Textbox autocomplete source to specific column in my datatable?
    how can i do that?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: how to set the Textbox autocomplete source to specific column in my datatable

    You'd just have to use a custom source and keep it up to date yourself by handling the appropriate events of your DataTable.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Member
    Join Date
    Mar 2009
    Location
    India
    Posts
    41

    Re: how to set the Textbox autocomplete source to specific column in my datatable

    hiii jmm r u there

  4. #4

    Thread Starter
    Hyperactive Member snakeman's Avatar
    Join Date
    Aug 2006
    Posts
    351

    Re: how to set the Textbox autocomplete source to specific column in my datatable

    hey
    i know i have to use a custom source but what is the source exactly?

  5. #5

    Thread Starter
    Hyperactive Member snakeman's Avatar
    Join Date
    Aug 2006
    Posts
    351

    Re: how to set the Textbox autocomplete source to specific column in my datatable

    Quote Originally Posted by Naveen sharma View Post
    hiii jmm r u there
    what??????

    if you want jimm then send PM to him .

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: how to set the Textbox autocomplete source to specific column in my datatable

    Quote Originally Posted by snakeman View Post
    hey
    i know i have to use a custom source but what is the source exactly?
    You set the AutoCompleteSource to Custom and then you have to add and remove items directly to the AutoCompleteCustomSource, which is itself a collection. You're going to have to manually get the data out of the column of your DataTable and manually add each value to the collection. You'll then need to handle the appropriate events of the DataTable to detect when a row is added, editied or deleted and then manually update the auto-complete collection.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: how to set the Textbox autocomplete source to specific column in my datatable

    Assuming that you're using .NET 3.5, the easiest way to populate the auto-complete collection from the DataTable is using LINQ:
    vb.net Code:
    1. Me.TextBox1.AutoCompleteCustomSource.AddRange((From row In myDataTable.Rows.Cast(Of DataRow)() _
    2.                                                Select CStr(row("SomeColumn"))).ToArray()
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Hyperactive Member snakeman's Avatar
    Join Date
    Aug 2006
    Posts
    351

    Re: how to set the Textbox autocomplete source to specific column in my datatable

    thank you so much

  9. #9
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    493

    Re: how to set the Textbox autocomplete source to specific column in my datatable

    Quote Originally Posted by jmcilhinney View Post
    Assuming that you're using .NET 3.5, the easiest way to populate the auto-complete collection from the DataTable is using LINQ:
    vb.net Code:
    1. Me.TextBox1.AutoCompleteCustomSource.AddRange((From row In myDataTable.Rows.Cast(Of DataRow)() _
    2.                                                Select CStr(row("SomeColumn"))).ToArray()
    hi jmc

    i tried the above on form load but it says

    HTML Code:
     'Cast' is not a member of 'System.data.datarowcollection'
    i am not using linq as i have no knowledge of it
    can u pls. guide
    thankx

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: how to set the Textbox autocomplete source to specific column in my datatable

    Quote Originally Posted by kuldevbhasin View Post
    hi jmc

    i tried the above on form load but it says

    HTML Code:
     'Cast' is not a member of 'System.data.datarowcollection'
    i am not using linq as i have no knowledge of it
    can u pls. guide
    thankx
    Are you using .NET 3.5? If not then LINQ and extension methods, which Cast is, are not available to you.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    493

    Re: [RESOLVED] how to set the Textbox autocomplete source to specific column in my da

    thankx jmc for replying. i am using 3.5 as i am using vb.net 2008
    do i have to include anything ?
    i am using a webservice and gathering the data with the web reference.
    there r about 12500 records in the master which i would want to fill in the autocomplet of the master selection
    thankx

  12. #12
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    493

    Re: [RESOLVED] how to set the Textbox autocomplete source to specific column in my da

    i am doint it in the following manner :
    vb Code:
    1. Dim iRowCount As Integer = dTableMasterHelp.Rows.Count - 1
    2.         Dim i As Integer = 0
    3.         For i = 0 To iRowCount
    4.             Dim iRow As DataRow = dTableMasterHelp.Rows(i)
    5.             txtCustName.AutoCompleteCustomSource.Add(iRow!Name.ToString())
    6.         Next

    but it is taking a lot of time and i feel that ur method would b much simpler and fast
    hope to hear from u soon.
    thankx

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] how to set the Textbox autocomplete source to specific column in my da

    Quote Originally Posted by kuldevbhasin View Post
    thankx jmc for replying. i am using 3.5 as i am using vb.net 2008
    That doesn't necessarily follow as VB 2008 can target .NET 2.0, 3.0 or 3.5.

    You'll need to have imported the System.Linq namespace.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #14
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    493

    Re: [RESOLVED] how to set the Textbox autocomplete source to specific column in my da

    thankx a lot jmc i got it working as u said it was targeting .net 2.0 and hence it was giving a error..
    thankx a lot for being a great help as always

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width