Combo box refresh issue - Windows forms

  • Thread starter Thread starter czarvk
  • Start date Start date
C

czarvk

Guest
Hi, I have an issue with the combo box. Just to simply my question I created a small windows form with a combo box. I am calling this form from a button on a menu. As you can see there is a timer in the form that refresh's every 2 seconds. Within the timer method "timerUpdateVATInfo_Tick" we write selected combo text into a string "po". This is how the sequence of execution is

1.) First I open Main menu and click on the comboTest form button to open the form. Select some random value from the com bo drop down.

2.) Close the comboTest form and re-open again. Please keep the menu open don't close it yet. Again select some random value from the drop down. Let us say you selected "USA".

3.) This time put a break point on "timerUpdateVATInfo_Tick" method. Hover over "po", you will see it shows something other than what you selected, let us say "India".

As I keep doing F10 it loops between "USA" and "India". I would expect it to show me "USA" constantly but it randomly picks "India" or some other value. It doesn't do that the first I open the comboTest form from the menu. It only does that when close the comboTest form and re-open it while the main menu is still running.


Please help. Thanks in advance.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LMS.cheese.make
{
public partial class ComboTest : Form
{

public ComboTest()
{
InitializeComponent();
}

private void ComboTest_Load(object sender, EventArgs e)
{
loadComboPOs(comboCurrentPO1);
InitTimer();
comboCurrentPO1.SelectedIndex = -1;
}

private Timer timer1;
public void InitTimer()
{
try
{
if (timer1 != null)
timer1.Stop();

timer1 = new Timer();
timer1.Tick += new EventHandler(timerUpdateVATInfo_Tick);
timer1.Interval = 2000; // in miliseconds
timer1.Start();
}
catch (Exception ex)
{

}
}

private void timerUpdateVATInfo_Tick(object sender, EventArgs e)
{
string po = comboCurrentPO1.Text;
//MessageBox.Show(po);
}


private void loadComboPOs(object sender)
{

comboCurrentPO1.Items.Add("Tokyo");
comboCurrentPO1.Items.Add("Japan");
comboCurrentPO1.Items.Add("China");
comboCurrentPO1.Items.Add("Russia");
comboCurrentPO1.Items.Add("India");
comboCurrentPO1.Items.Add("USA");

}

}
}


Code for Menu form:

private void pictureBox1_Click(object sender, EventArgs e)
{
ComboTest fDOP = new cheese.make.ComboTest();
fDOP.ShowDialog();
}




svk

Continue reading...
 
Back
Top