c# - Searching in databound comboBox? -


Friends I have a combo box that is configured to work as a dropdown list. It is being populated through the database, it is working without losslessness.

Now what I want to do is this: For example, I have a combo box that is receiving the "Name" column from the database table "tblPersons" and displaying it. If, for example, database table of 4 entries "tblPersons" are

in
  1. Ali Khan
  2. Ahmed Khan
  3. Bilal Khan
  4. Bilal Farooqi

when I write "Ahmd Faruki" combo box (must be editable combo box and press once I "Ahmad") and enter her database The table should be searched in "TBPerson" - if "Ahmed Farooqui" is found - it should be selected, if "Ahmed Farooqui" is not found - then They do what I want to create a new entry in the database table to ask me "TblPersons", if I click on "Yes" should open another form to add a new person and if I click on "No" , Then he should not do anything.

How should I do this? I'm new to C #, so any help would be greatly appreciated.

EDIT: This is my test form, here I have a text box that will be used to enter the name, the text box must be searched for the name in the database, then if the names are found then their Display number and email from the database in the respective textbox. If not found, the message box should be asked to make the user a new person and if yes clicked, then switch to another form (where the user will make a new person).

The image description Enter

< Div class = "post-text" itemprop = "text">

Call the fillCombo function in your form load and assign the cmb_SelectedValueChanged event to your combobox. Do not forget to set in AutoComplete property kickboxes.

  cmb.autocompletemode = auto integer. Recommended Private Zero fillCombo () {string sql = "select id, name, number, email by tblPerson"; SqlConnection CNN = New SqlConnection ("Connection String"); Cnn.Open (); SqlDataAdapter da = New SqlDataAdapter (SQL, CNN); Datatable dt = new datatable (); Da.Fill (DT); Cmb.ValueMember = "ID"; Cmb.DisplayMember = "name"; Cmb.DataSource = dt; } Private void cmb_SelectedValueChanged (object sender, EventArgs e) {if (cmb.SelectedItem! = Null) {txtNumber.Text = ((DataRow) cmb.SelectedItem) [ "No."]. ToString (); TxtEmail.Text = ((DataRow) cmb.SelectedItem) ["Email"]. ToString (); }} Private void cmb_Validating (object sender, CancelEventArgs e) {if (cmb.SelectedItem == null) {if (MessageBox.Show ( "Do you want to create a new person?", MessageBoxButtons.YesNo) == DialogResult.Yes ) {FrmNewPerson person = new frmNewPerson (); Person.Name = cmb.Text; If (person.ShowDialog () == DialogResult.Yes) {fillCombo (); Datarov Dr. = ((DataTable) CMB. Datasource). Select ("name = '" + person. Name + "'") [0]; Cmb.SelectedValue = Convert.ToInt32 (Dr. ["id"]); }} And {txtNumber.Text = string.Emtpy; TxtEmail.txt = string.Emtpy; }}}  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -