I made a small sample program to illustrate my problem. The program consists of one form with one TableLayoutPanel: tableLayoutPanel1 one NumericUpDown: coins and one button: flip. When flip is pressed, pressing tableLayoutPanel1 is dynamically filled with coins. Add lines. Each line consists of one ComboBox with the "Heads" and "Tails" elements. One of these elements is selected by drawing a random number for each row. The code is as follows:
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void draw_Click(object sender, EventArgs e)
{
tableLayoutPanel1.Controls.Clear();
string[] results = { "Heads", "Tails" };
int nCoins = Convert.ToInt32(coins.Value);
Random random = new Random();
for(int i = 0; i < nCoins; i++) {
ComboBox coin = new ComboBox();
coin.Items.AddRange(results);
coin.SelectedIndex = random.Next(0, 2);
tableLayoutPanel1.Controls.Add(coin, 0, i);
}
}
}
}
My problem is that the selected item in each ComboBox has focus, i.e. blue. How to stop this? I tried calling coin.SelectionLength = 0; but this does not work :-(.
For any answers in advance!
Andreas Werner Paulsen