473,473 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

drop down list

30 New Member
am new in c# and i have some problems that o need some help
i have t text box that when i type the characters i want a drop down list to be appeard under the text box sorted according the characters that i type.
if i type ont he textbox "myn" the dropdown list to be appeaerd sorted and according the first characters that i write.also this values that are going to be display must be retrieve from a database from sql server.
i try doing something but i find dificulties.

Expand|Select|Wrap|Line Numbers
  1. class MyListBoxItem 
  2.     {
  3.  
  4.     public MyListBoxItem(int ItemData, string Text)
  5.         {
  6.             text = Text;
  7.             itemData = ItemData;
  8.         }   
  9.     public int ItemData
  10.         {
  11.         get
  12.             {
  13.             return itemData;
  14.             }
  15.         set
  16.             {
  17.             itemData = value;
  18.             }
  19.         }
  20.      public override string ToString()
  21.          {
  22.          return text.Trim();
  23.          }
  24.      protected string text;
  25.      protected int itemData;
  26.     }
  27.  
  28.         private void textBox1_TextChanged(object sender, EventArgs e)
  29.         {
  30.  
  31.             if (capturesymptom.Text.Length > 1)
  32.             {
  33.  
  34.                 SearchName();
  35.  
  36.             }
  37.  
  38.  }
  39.  
  40.     private void SearchName()
  41.     {
  42.         ListBox ListBox1 = new ListBox();
  43.         ListBox1.Items.Clear();
  44.         SqlConnection dataConnectionSymptom = null;
  45.         DataSet datasetsymptom = null;
  46.  
  47. //connection with the database//
  48.  
  49.         SqlDataAdapter dataAdaptersymptom = new SqlDataAdapter(querysymptom);
  50.         dataAdaptersymptom.Fill(datasetsymptom, "[Symptoms]");
  51.  
  52.  
  53.         datasetsymptom.DataSetName = "[DiseaseName]";
  54.         dataConnectionSymptom.Close();
  55.  
  56.         for (int i = 0; i <  datasetsymptom.Tables["[Symptoms]"].Rows.Count; i++)
  57.             {
  58.                 ListBox1.Items.Add(new MyListBoxItem(Convert.ToInt32(datasetsymptom.Tables["Symptoms"].Rows[i][0].ToString()),datasetsymptom.Tables["Symptoms"].Rows[i][1].ToString()));
  59.             }
  60.             try
  61.             {
  62.  
  63.   //i thing the problem is in this step.i don't know how i should diplay the data that i get from the database under my text box
  64.             }
  65.             catch
  66.             {
  67.                 MessageBox.Show("search failed");
  68.             }
  69.             finally
  70.             {
  71.                 dataConnectionSymptom.Close();
  72.             }
  73.  
  74. }
  75.  
i thing that the problem is in the try statement.i dont know hot to diplay the data.
beside that i don't know if the mylistboxitem is correct.
the values that are going to be display are vchar.
Nov 10 '07 #1
9 1716
kenobewan
4,871 Recognized Expert Specialist
Have you tried using a combobox?
Nov 11 '07 #2
prokopis
30 New Member
no i did't try a compobox.i don't want a combobox.this that i want is to have a text box.the user will write a word and from the textbox will load all the data according the database a listbox will appeard.
ex fromt he database

ID Symptom
1 Qname1
2 Qname2
3 Pname1
4 Pname2
5 Zname
if the user type Qna then on the listbox the Qname1 and Qname2 must be appeared.
Nov 11 '07 #3
kenobewan
4,871 Recognized Expert Specialist
Suggest you try a combobox.
Nov 12 '07 #4
prokopis
30 New Member
Suggest you try a combobox.
my problem is how to load the data from the database.
am not using combobox because on the database there are 1000 record.i don't want all those records to be loaded each time.i want only to be loaded sorted the user type on the textbox
Nov 12 '07 #5
nateraaaa
663 Recognized Expert Contributor
my problem is how to load the data from the database.
am not using combobox because on the database there are 1000 record.i don't want all those records to be loaded each time.i want only to be loaded sorted the user type on the textbox
You could still use a combobox. You would just have to modify your stored procedure to only return records from the database that start with or contain (whatever you are trying to show the user) the the text that the user enters in the textbox. Populate your combobox with the records returned from the stored procedure. If you do this your calls to your database and populating your combobox will occur in the TextChanged event of your textbox.

Nathan
Nov 12 '07 #6
prokopis
30 New Member
You could still use a combobox. You would just have to modify your stored procedure to only return records from the database that start with or contain (whatever you are trying to show the user) the the text that the user enters in the textbox. Populate your combobox with the records returned from the stored procedure. If you do this your calls to your database and populating your combobox will occur in the TextChanged event of your textbox.

Nathan
ok.your idea is very good but there is a small problem.how am i going to do this.i just start using c# and i don't know a lot of things.if you could help me how to do this i will appreciate.
Nov 12 '07 #7
kenobewan
4,871 Recognized Expert Specialist
prokopis has already told you how to do it, if you don't know where to start then you need to complete the course that you are doing to learn the basics. Then show us your code if you have a problem or error. Thanks.
Nov 13 '07 #8
prokopis
30 New Member
i have try it but i have a question.
before i write something on the box and just oush the arrow to show all the list is not sorted.how can i sort it?
Nov 15 '07 #9
terminul
6 New Member
Maybe you can try the Ajax Control Toolkit's AutoCompleteExtender.

it is simple to implement (via web services or Page /WebMethods)

http://www.asp.net/AJAX/AjaxControlT...oComplete.aspx

just download the toolkit zip and install the dlls to get these ajax controls, autocompleteextender is just one of many.

also supports caching
Nov 17 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Miguel Dias Moura | last post by:
Hello, i have an ASP.NET / VB page where i have a few 4 groups of Drop Down Lists. Each group of Drop Down Lists include 3 Drop Down Lists for date such as: DAY, MONTH, and YEAR. I don't want...
3
by: Don Wash | last post by:
Hi There! I have a Server-side Drop-down box in ASP.NET (VB) page. What do I do to widen the Drop down box's Pull-Down list's width? I'm not talking about the Drop-down box's width but the box...
13
by: Leszek Taratuta | last post by:
Hello, I have several drop-down lists on my ASP.NET page. I need to keep data sources of these lists in Session State. What would be the most effective method to serialize this kind of data...
2
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will...
5
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1);...
1
by: pmelanso | last post by:
Hello, I have a drop down list which is dynatically loaded from a database and I have a second drop down list that is also dynatically loaded depending on what is selected in the first drop down...
8
by: Ed Dror | last post by:
Hi there ASP.NET 2.0 VB & SQL Express Lest take Northwind Categories Products as example I create a table that hold these two together and I create a stored procedure like select ProductID,...
5
by: ashok893 | last post by:
I'm using two drop down list ina form. I have generated the first drop down list from MySQL database. When i select an option from first drop down list, i have to generate second drop down list...
4
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me...
3
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.