Basically I have two categories:
Category - A
Category - B
I will select category - A and generate number serials from 1 to 10. display in combobox 2 and save it.
I will then select category B and generate number serials from 1 to 10, display in combobox 2 and save it.
when I close and open back the application, I want to see only those serials generated in category A in comboBox2.
I have been trying to do it by adding a datagridview but it merges both category serials. Screenshot
Category - A -- > Serials{1,2,3,4,5,6,7,8,9,10}
Category - B -- > Serials{11,12,13,14,15,16,17,18}
.
so when I select Category A, I want to see only A serials in comboBox2 and nothing else.
when I select Category B, I want to see only B serials in comboBox2 and nothing else.
private void GenSerialBookButton_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == 0)
{
from = int.Parse(textBox2.Text);
to = int.Parse(textBox3.Text);
result = to - from;
for (int i = 0; i <= result; i++)
{
comboBox2.Items.Add(from + i);
this.SerialBookDataBaseBindingSource.AddNew();
dataGridView1.Rows[i].Cells[1].Value = from + i;
}
MessageBox.Show("Serial Book Generated Success", "Success");
}
if (comboBox1.SelectedIndex == 1)
{
from = int.Parse(textBox2.Text);
to = int.Parse(textBox3.Text);
result = to - from;
for (int i = 0; i <= result; i++)
{
comboBox2.Items.Add(from + i);
this.SerialBookDataBaseBindingSource.AddNew();
dataGridView1.Rows[i].Cells[1].Value = from + i;
}
MessageBox.Show("Serial Book Generated Success", "Success");
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
// Clear previous list
a: if (comboBox2.Items.Count > 0)
{
comboBox2.Items.RemoveAt(0);
goto a;
}
if (comboBox1.SelectedIndex == 0)
{
comboBox2.Items.Clear();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
comboBox2.Items.Add(row.Cells[1].Value);
MessageBox.Show("Adding: " + (row.Cells[1].Value.ToString()));
comboBox2.Refresh();
}
}
if (comboBox1.SelectedIndex == 1)
{
comboBox2.Items.Clear();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
comboBox2.Items.Add(row.Cells[1].Value);
MessageBox.Show("Adding: " + (row.Cells[1].Value.ToString()));
comboBox2.Refresh();
}
}
}
}
}