Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9095843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:42:25+00:00 2026-06-16T23:42:25+00:00

I want to set the autocomplete feature to the textbox using LINQ. I already

  • 0

I want to set the autocomplete feature to the textbox using LINQ. I already did in one way with sqlCommands. The code is

  OleDbCommand cmdinst = new OleDbCommand("select distinct cst_City from cstTable", con);
  OleDbDataReader drinst = cmdinst.ExecuteReader();
  AutoCompleteStringCollection instcol = new AutoCompleteStringCollection();
  while (drinst.Read())
  {
      instcol.Add(drinst.GetString(0));
  }
  txtCity.AutoCompleteCustomSource = instcol;

With this I can add the autocomplecustom source to the textbox. Now I want to add the same feature with LINQ. Please any one help me..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T23:42:30+00:00Added an answer on June 16, 2026 at 11:42 pm

    Adding strings to AutoCompleteStringCollection one by one is not efficient. Because when each string is added inner array list ensures its capacity and resizes storage (makes it two times bigger) if there is not enough space for new string. Also fore each added string CollectionChangedEvent will try to fire. When you adding values via AddRange storage is resized only once, and CollectionChangedEvent is fired only once.

    Also you can simply apply Distinct operator, instead of grouping and selecting first group.

    var db = FooDataContext();
    var cities = db.cstTable.Select(c => c.cst_City).Distinct().ToArray();
    
    AutoCompleteStringCollection instcol = new AutoCompleteStringCollection();
    instcol.AddRange(cities);
    txtCity.AutoCompleteCustomSource = instcol;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want set interfaceOrientation in one UIView as LandscapeLeft and Portrait in other UIView.
I am using jquery autocomplete combobox and everything is ok. But I also want
I'm using Jorn Zaefferer's Autocomplete query plugin, http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ I have options set so it
I have a jquery-ui autocomplete text box and i want to set a default
I am using jQuery's autocomplete and I have it set up in the following
I am using the AJAX autocomplete add-on to the <asp:textbox> control. I have everything
I am using jquery autocomplete , and I've set these vars $(#some_id).autocomplete(search.php?in=somewhere, { width:
Currently when I want to set html attributes like maxlength and autocomplete, I have
I want to fill a text input in my form using an autocomplete widget
i want set the visibility to itemized overlay in map view. if the zoom

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.