Update Combobox Contents

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi:
I have a combobox (in form 1) whose items are populated from a table. In
form 2 there is a data entry for the same table. How do I reflect the
changes to the combobox in form 1 as soon as the data entered in form 2 is
saved in the table? Thanks in advance.
 
Hi,

One way to accomplish this is rebind the data in the combobox in an event
that fires upon completion of the data entry. This way the combobox will
reflect the changes of the data entered on your form.

I hope this helps.
 
First of all I write a class in a seperate file as this
using System;

using System.Windows.Forms

public class Watcher

{

private System.Windows.Forms.ComboBox combo;


public Watcher()

{

}

public Watcher(ref System.Windows.Forms.ComboBox cb)

{

this.combo = cb;

}


public void AddItem()

{

this.combo.Items.Add("SerhaD");

}

}



Both Form1 and Form 2 have an instance of this class. In The Form 1 it is a
private, Form2's is public member

//////In your Form1.comboBox fill function do

watcherForm1 = new Watcher(ref comboBox1);

//////while constructing Form2 Do this

Form2 f2 = new Form2();

f2.watcherForm2 = watcherForm1;

fe.ShowDialog();

/////// In the Form2 you may call AddItem function of Watcher Class

watcherForm2.AddItem(); //this adds SerhaD to the combo

////Turn to the Form1 and Look at the Combo and that's it

SerhaD is added to the Combo from Form2 !

Hope you get the idea ,
 
Back
Top