Sultan Mirza

Sultan Mirza

  • 2.1k
  • 5
  • 269

Fill description textbox on the basis of value selected in partnumber

Aug 20 2020 5:10 AM
I have 2 textboxes txtPartNum and txtDesc. partnumber is autocomplete from database

 
i have the partnumber and description saved in list _partNum. how do i get the description text box filled on the basis of partnumber selected on textChanged or keyDown event. code suggestion please.? 
  1. public class PartNumbers    
  2. {    
  3.     public string parts { getset; }    
  4.     public string descr { getset; }    
  5. }    
  6.     
  7. List<PartNumbers> _partNum = new List<PartNumbers>();    
  8.     
  9. public void partNumberLoad()  
  10. {    
  11.     try    
  12.     {    
  13.         string query = "select itmPartNumber, itemDescr from vstItems";    
  14.         SqlCommand cmd = new SqlCommand(query, MainClass.con);    
  15.         if (MainClass.con.State == ConnectionState.Closed)    
  16.             MainClass.con.Open();    
  17.         SqlDataReader sdr = cmd.ExecuteReader();    
  18.         AutoCompleteStringCollection autoPart = new AutoCompleteStringCollection();    
  19.         while (sdr.Read())    
  20.         {    
  21.             autoPart.Add(sdr["itmPartNumber"].ToString());    
  22.             PartNumbers partNumbers = new PartNumbers { parts = sdr["itmPartNumber"].ToString(), descr = sdr["itemDescr"].ToString() };    
  23.                     _partNum.Add(partNumbers);    
  24.         }    
  25.         sdr.Close();    
  26.         cmd.Connection.Close();    
  27.         txtPartNum.AutoCompleteMode = AutoCompleteMode.Suggest;    
  28.         txtPartNum.AutoCompleteSource = AutoCompleteSource.CustomSource;    
  29.         txtPartNum.AutoCompleteCustomSource = autoPart;                    
  30.     }  
  31. } 

Answers (1)