In Quize method I am passing qestions which contains set of all my Questions to be displayed using DisplayQuestion(),Question is my Class, Problem is that I am getting only First Question displayed, how can I get them displayed when i click on listviewItem if suppose questionscontains 10 Questions,than in listviewItem I have displayed numbers(1 2 3 4 5 ....10),when i click on each number how do i display that particular Questiondisplyed on click and if not clicked how all Questions displayed one by one using timer
public partial class GroupExmStart : Form
{
string[] randomQsn = new string[totQsn + 1]; //totQsn is the total number of question for e.g.10
public GroupExmStart(string GroupName, string DurationID)
{
InitializeComponent();
this.GrpID=GroupName;
TopiID=db.GetTopicIDForGroup(GrpID);
string[] conf = db.GetConfiguration(Convert.ToInt16(DurationID)).Split('|');
Question qsn = new Question();
var questions = qsn.Foo(TopiID, conf);
int z = Quiz(questions);
totQsn = Convert.ToInt16(conf[0]);
for (int kk = 1; kk <= totQsn; kk++)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = kk.ToString();
listView1.Items.Add(lvi);
}
randomQsn = new string[totQsn + 1];
timer1.Interval = 1000; //1000ms = 1sec
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Start();
}
int Quiz(List<Question> questions)
{
foreach (Question question in questions)
{
DisplayQuestion(question);
}
return 0;
}
private void DisplayQuestion(Question question)
{
string Q = question.Text;
label5.Text = Q;
string OP1 = question.Option1;
string OP2 = question.Option2;
string OP3 = question.Option3;
string OP4 = question.Option4;
radioButton12.Text = OP1;
radioButton11.Text = OP2;
radioButton10.Text = OP3;
radioButton9.Text = OP4;
}
private void listView1_MouseClick(object sender, MouseEventArgs e)
{
if (randomQsn.GetLength(0) >= 0)
{
if (listView1.SelectedItems.Count > 0)
{
//here how should i get That particular Question so that i can display it
//something like this ? //Convert.ToInt16(listView1.SelectedItems[0].SubItems[0].Text)
DisplayQuestion(question);
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
tik++;
if (tik == 60)
{
label1.Text = (Convert.ToInt16(label1.Text) - 1).ToString();
tik = 0;
}
}
}
Thanks for any help in advance
The following is what you are looking for. You must grab the text of the list view item and use that as the index of the question.
if (listView1.SelectedItems.Count > 0)
{
var q = Convert.ToInt16(listView1.SelectedItems[0].Text);
var selectedQuestion = questions[q - 1];
DisplayQuestion(selectedQuestion);
}
In order for this to work, modify your constructor to the following:
private List<Question> questions;
public partial class GroupExmStart : Form
{
string[] randomQsn = new string[totQsn + 1]; //totQsn is the total number of question for e.g.10
public GroupExmStart(string GroupName, string DurationID)
{
InitializeComponent();
this.GrpID=GroupName;
TopiID=db.GetTopicIDForGroup(GrpID);
string[] conf = db.GetConfiguration(Convert.ToInt16(DurationID)).Split('|');
Question qsn = new Question();
/// THIS IS MODIFIED //
questions = qsn.Foo(TopiID, conf);
int z = Quiz(questions);
totQsn = Convert.ToInt16(conf[0]);
for (int kk = 1; kk <= totQsn; kk++)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = kk.ToString();
listView1.Items.Add(lvi);
}
randomQsn = new string[totQsn + 1];
timer1.Interval = 1000; //1000ms = 1sec
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Start();
}
Related
I want to create link label dynamically on each listview row.. So i wrote following code to do it..
int l = 0;
private void Timer1_Tick(object sender, EventArgs e)
{
string[] idlist = textBox1.Text.Split('\n');
//string[] title = textBox2.Text.Split('\n');
//string[] shippingcost = textBox3.Text.Split('\n');
//string[] newuserbonus = textBox4.Text.Split('\n');
//string[] itemprice = textBox5.Text.Split('\n');
string[] linkbuilder = textBox6.Text.Split('\n');
string[] title = title1.Split('\n');
string[] shippingcost = SC.Split('\n');
string[] newuserbonus = NUB.Split('\n');
string[] itemprice = IP.Split('\n');
//Button btn = new Button();
//btn.Text = "View";
//btn.BackColor = SystemColors.ButtonFace;
// Point p = this.listView1.Items[2].Position;
//p.X -= 21;
//btn.Location = p;
// btn.Size = this.listView1.Items[2].Bounds.Size;
// btn.Click += new EventHandler(btn_Click);
LinkLabel ln = new LinkLabel();
string A = null;
if (title[l] != null && shippingcost[l] != null && idlist[l] != null && itemprice[l] != null)
{
ListViewItem items = new ListViewItem((l + 1).ToString());
items.SubItems.Add(title[l]);
items.SubItems.Add(shippingcost[l]);
items.SubItems.Add(idlist[l]);
items.SubItems.Add(itemprice[l]);
// items.SubItems.Add("views");
// this.listView1.Controls.Add(btn);
ListView.Items.Add(items);
ln.Parent = ListView;
ln.Text = "View"+(l+1);
//btn.BackColor = SystemColors.ButtonFace;
Point p = this.ListView.Items[l].Position;
p.X += 1000;
p.Y += ListView.Items[l].Index;
ln.Location = p;
//ln.Size = new Size(100, 50);
this.ListView.Controls.Add(ln);
label2.Text = l.ToString();
int Ab = l;
ln.Click += (object senderw, EventArgs ew) =>
{
// MessageBox.Show(i.ToString()); // i= 3
string strUrl = linkbuilder[Ab];
Process proc = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo(strUrl);
proc.StartInfo = startInfo;
proc.Start();
};
//if (listView1.Items.Count > 0)
// listView1.Items[listView1.Items.Count - 1].Remove();
l++;
}
if (l == 60)
{
timer1.Stop();
}
}
So i got following output, S
after scrolling the listview. I saw like following..
Then i saw, when i scroll the listview. View Link label are not moving. But my expectation is not this.. I want to move these link lables when scrolling and Number of View link label and Item Number should be same line and same number while scrolling. Like 1st photo... I have no idea how to do it...
Could somebody help me to get fixed this..?
I need to display an unselected ComboBox value.
I have 10 ComboBoxes with tag values 1 through 10.
When I select a ComboBox with a tag value of 1, I have to check what is displayed from the ComboBox that has a tag value of 2.
Selecting a ComboBox with a tag value of 5 should give me the value of the ComboBox that has a tag value of 6.
public partial class workPlacePlan : Form
{
public workPlacePlan()
{
InitializeComponent();
}
private void workPlacePlan_Load(object sender, EventArgs e)
{
this.MaximumSize = this.Size;
this.MinimumSize = this.Size;
int cboId;
int i = 1;
string cboName; int c = 1;
var items = new Dictionary<int, string>();
ComboBox[] cbo = {
cbo_1, cbo_2
};
foreach(ComboBox cbos in cbo)
{
items.Add(0, "-------");
i = 1;
while (i <= 24)
{
cboId = i;
cboName = TimeSpan.FromHours(i).ToString("hh':'mm");
items.Add(cboId, cboName);
i++;
}
cbos.Tag = c;
cbos.DataSource = new BindingSource(items, null);
cbos.DisplayMember = "Value";
cbos.ValueMember = "Key";
items.Clear();
cbos.SelectedIndexChanged += new EventHandler(cboSelected);
c++;
}
}
public void cboSelected(object sender, EventArgs e)
{
ComboBox cb = ((ComboBox)sender);
int i_tmp;
int tg = Int32.Parse(cb.Tag.ToString());
if(tg % 2 == 0) //if is even
{
i_tmp= tg - 1;
}
else
{
i_tmp = tg + 1;
}
}
private void cmd_Save_Click(object sender, EventArgs e)
{
}
}
Solution:
public partial class workPlacePlan : Form
{
public workPlacePlan()
{
InitializeComponent();
}
private void workPlacePlan_Load(object sender, EventArgs e)
{
this.MaximumSize = this.Size;
this.MinimumSize = this.Size;
int cboId;
int i = 1;
string cboName; int c = 1;
var items = new Dictionary<int, string>();
ComboBox[] cbo = {
cbo_1_0, cbo_1_1, cbo_2_0, cbo_2_1, cbo_3_0, cbo_3_1, cbo_4_0, cbo_4_1, cbo_5_0, cbo_5_1, cbo_6_0, cbo_6_1,
cbo_13_0,cbo_13_1,cbo_14_0,cbo_14_1,cbo_15_0,cbo_15_1,cbo_16_0,cbo_16_1,cbo_17_0,cbo_17_1,cbo_18_0,cbo_18_1,
cbo_19_0,cbo_19_1
};
foreach(ComboBox cbos in cbo)
{
items.Add(0, "-------");
i = 1;
while (i <= 24)
{
cboId = i;
cboName = TimeSpan.FromHours(i).ToString("hh':'mm");
items.Add(cboId, cboName);
i++;
}
cbos.Tag = c;
cbos.DataSource = new BindingSource(items, null);
cbos.DisplayMember = "Value";
cbos.ValueMember = "Key";
cbos.SelectedIndex = 0;
items.Clear();
cbos.SelectedIndexChanged += new EventHandler(cboSelected);
c++;
}
}
public void cboSelected(object sender, EventArgs e)
{
ComboBox cb = ((ComboBox)sender);
int i_tmp;
int tg = Int32.Parse(cb.Tag.ToString());
int idx;
if(tg % 2 == 0) //if is even
{
i_tmp= tg - 1;
}
else
{
i_tmp = tg + 1;
}
//string y = cb.GetItemText(cb.SelectedItem);
//MessageBox.Show(y.ToString());
foreach (ComboBox cbt in panel1.Controls.OfType<ComboBox>()) {
if(Int32.Parse(cbt.Tag.ToString()) == Int32.Parse(i_tmp.ToString()))
{
idx = Int32.Parse(cbt.SelectedIndex.ToString());
cbt.SelectedIndex = idx;
MessageBox.Show(cbt.SelectedIndex.ToString());
}
}
}
private void cmd_Save_Click(object sender, EventArgs e)
{
}
}
Ok, so with the help of awesome guys here on Stackoverflow I have created my array like this.
public partial class Form1 : Form
{
string[] Brands = new string[10];
int brandNo;}
public Form1()
{
InitializeComponent();
Brands[0] = "Yamaha"; //ok
Brands[1] = "Suzuki"; //ok
Brands[2] = "Harley"; //ok
Brands[3] = "Kawasaki"; //ok
brandNo = 4;
}
private void buttonAddbrand_Click(object sender, EventArgs e)
{
if (brandNo >= 10)
return; //cannot add more brand
Brands[brandNo++] = textBoxMerk.Text;
var Merk = Brands
listBoxMotoren.Items.Clear();
listBoxMotoren.Items.AddRange(Merk);
With this code I want to display the filled values of the array in my listbox. But I get the following error:
value can not be null.
Help will be much appreciated.
Firstly, be careful of where you put your curly bracket as to ensure that the code can be compiled.
public partial class Form1 : Form
{
string[] Brands = new string[10];
int brandNo;} //<- off-placed
Secondly, since you start with making the array as your DataSource (and not using Items.Add or Items.AddRange to your listBoxMotoren, it may be consistent if you doing so on addition or removal of your item in the listBoxMotoren.
private void buttonAddbrand_Click(object sender, EventArgs e) {
if (brandNo >= 10)
return; //cannot add more brand
Brands[brandNo++] = textBoxMerk.Text;
listBoxMotoren.DataSource = null; //the cheapest and dirtiest trick to do this
listBoxMotoren.DataSource = Brands; //Maintaining the style, use `DataSource` to accommodate new data
}
Lastly, if you want to remove the brand item at will, you might need another Control in your Form1 as an input for which item in the brand you want to get optionally delete. But beware that this may "destroy" the sequence of your items and thus you may need to "re-sequencing" your item.
Now, suppose you use NumericUpDown to delete and trigger the deletion using buttonDeletebrand then you should do something like this
private void buttonDeletebrand_Click(object sender, EventArgs e) {
int indexToDelete = (int)numericUpDownMotorenNumberDeleted.Value; //note the casting to (int)
if (indexToDelete < 0 || indexToDelete >= brandNo || brandNo <= 0) //can only delete index no [0] to [brandNo-1], and if the brand no > 0
return; //invalid index
for (int i = indexToDelete; i < brandNo - 1; ++i)
Brands[indexToDelete] = Brands[indexToDelete + 1]; //resequencing
Brands[brandNo - 1] = string.Empty; //removes the last element after resequencing
listBoxMotoren.DataSource = null; //remember the cheapest and dirtiest trick?
listBoxMotoren.DataSource = Brands;
--brandNo; //reduce the brandNo by 1
}
In total, you need all of them combined:
public partial class Form1 : Form {
string[] Brands = new string[10];
int brandNo;
public Form1() {
InitializeComponent();
Brands[0] = "Yamaha";
Brands[1] = "Suzuki";
Brands[2] = "Harley";
Brands[3] = "Kawasaki";
brandNo = 4;
listBoxMotoren.DataSource = Brands;
}
private void buttonAddbrand_Click(object sender, EventArgs e) {
if (brandNo >= 10)
return;
Brands[brandNo++] = textBoxMerk.Text;
listBoxMotoren.DataSource = null;
listBoxMotoren.DataSource = Brands;
}
private void buttonDeletebrand_Click(object sender, EventArgs e) {
int indexToDelete = (int)numericUpDownMotorenNumberDeleted.Value;
if (indexToDelete < 0 || indexToDelete >= brandNo || brandNo <= 0)
return;
for (int i = indexToDelete; i < brandNo - 1; ++i)
Brands[indexToDelete] = Brands[indexToDelete + 1];
Brands[brandNo - 1] = string.Empty;
listBoxMotoren.DataSource = null;
listBoxMotoren.DataSource = Brands;
--brandNo;
}
}
i'm pretty sure this code do not even compile....
int brandNo;} <- "}" ???
var Merk = Brands <- ";" missing and (var Merk) not needed
locking at this code i guess the problem is in
check
if (listBoxMotoren != null && listBoxMotoren.Items.Any())
listBoxMotoren.Items.Clear();
and of cource
if (listBoxMotoren != null && Brands != null)
listBoxMotoren.Items.AddRange(Brands);
if listboxMotoren is null the form is not initialized yet as long listBoxMotoren is a form Control
public partial class Form1 : Form
{
string[] Brands = new string[10];
int brandNo;
public Form1()
{
InitializeComponent();
Brands[0] = "Yamaha"; //ok
Brands[1] = "Suzuki"; //ok
Brands[2] = "Harley"; //ok
Brands[3] = "Kawasaki"; //ok
brandNo = 4;
listBoxMotoren.DataSource=Brands;//asssiign the current list to //listbox
}
private void buttonAddbrand_Click(object sender, EventArgs e)
{
if (brandNo >= 10)
return; //cannot add more brand
Brands[brandNo++] = textBoxMerk.Text;
listBoxMotoren.DataSource = null; //make the list empty
listBoxMotoren.DataSource = Brands;// assgin it new list
}
When I select a particular item in ListView item, I am able to display that particular item, and when the form loads I am getting the last item displayed by default (say the 10th item). However, what I want is to display the first item by default. How can I do this? I tried to do something like
listView1.Items[1].Selected = true;
but it's not working:
public partial class GroupExmStart : Form
{
string[] totDisplayQsn = null;
string[] QAndA = null;
string[] words = null;
private List<Question> questions;
ListViewItem lvi;
public GroupExmStart(string GroupName, string DurationID)
{
InitializeComponent();
this.GrpID=GroupName;
TopiID=db.GetTopicIDForGroup(GrpID);
string[] conf = db.GetConfiguration(Convert.ToInt16(DurationID)).Split('|');
Question qsn = new Question();
questions = qsn.Foo(TopiID, conf);
int z = Quiz(questions);
totQsn = Convert.ToInt16(conf[0]);
for (int kk = 1; kk <= totQsn; kk++)//using this I am adding items to listview
{
lvi = new ListViewItem();
lvi.Text = kk.ToString();
listView1.Items.Add(lvi);
}
totDisplayQsn = new string[totQsn + 1];
}
int Quiz(List<Question> questions)//using this I a passing set of questions to be displayed
{
foreach (Question question in questions)
{
DisplayQuestion(question);
}
return 0;
}
private void DisplayQuestion(Question question)//using this i am displaying questions
{
string Q = question.Text;
label5.Text = Q;
string OP1 = question.Option1;
string OP2 = question.Option2;
string OP3 = question.Option3;
string OP4 = question.Option4;
radioButton12.Text = OP4;
radioButton11.Text = OP4;
radioButton10.Text = OP4;
radioButton9.Text = OP4;
}
}
private void listView1_MouseClick(object sender, MouseEventArgs e)//using this i am selection particular item and displaying it
{
if (totDisplayQsn.GetLength(0) >= 0)
{
if (listView1.SelectedItems.Count > 0)
{
var q = Convert.ToInt16(listView1.SelectedItems[0].Text);
var selectedQuestion = questions[q-1];
DisplayQuestion(selectedQuestion);
}
}
}
Thanks in advance for any help.
Try this
listView1.SelectedItems[0].Focused = true;
To select the first item, access it by its zero based index. Place the code just after your items initialization code.
for (int kk = 1; kk <= totQsn; kk++)//using this I am adding items to listview
{
lvi = new ListViewItem();
lvi.Selected = false;
lvi.Text = kk.ToString();
listView1.Items.Add(lvi);
}
listView1.Items[0].Selected = true;
DisplayQuestion(questions[0]);
Remove the following code:
int Quiz(List<Question> questions)//using this I a passing set of questions to be displayed
{
foreach (Question question in questions)
{
DisplayQuestion(question);
}
return 0;
}
Ok try the below code:
ListViewItem foundItem = listView1.FindItemWithText("Select4", false, 0, true);
if (foundItem != null)
{
listView1.Items[foundItem.Index].Selected = true;
}
That's All.
I have the below code
public void panel_item_collections_Click(object sender, EventArgs e)
{
TextBox[] textbox_item_array = new TextBox[5];
item_textbox.Add(textbox_item_array);
textbox_item_array[0] = new TextBox();
textbox_item_array[0].Width = label_item_code.Width;
textbox_item_array[0].Height = 26;
textbox_item_array[0].Font = print_font_default;
textbox_item_array[0].Location = new Point(label_item_code.Location.X, 45 + (20 * row_count));
textbox_item_array[0].Name = string.Concat("item_code", row_count.ToString());
panel_item_collections.Controls.Add(textbox_item_array[0]);
textbox_item_array[0].Leave += new EventHandler(dynamic_text_item_code_Leave);
textbox_item_array[1] = new TextBox();
textbox_item_array[1].Width = label_item_descrition.Width;
textbox_item_array[1].Font = textbox_item_array[0].Font;
textbox_item_array[1].Location = new Point(label_item_descrition.Location.X, textbox_item_array[0].Location.Y);
textbox_item_array[1].Name = string.Concat("item_description", row_count.ToString());
panel_item_collections.Controls.Add(textbox_item_array[1]);
textbox_item_array[2] = new TextBox();
textbox_item_array[2].Width = label_item_price.Width;
textbox_item_array[2].Font = textbox_item_array[0].Font;
textbox_item_array[2].Location = new Point(label_item_price.Location.X, textbox_item_array[0].Location.Y);
textbox_item_array[2].Name = string.Concat("item_price", row_count.ToString());
panel_item_collections.Controls.Add(textbox_item_array[2]);
textbox_item_array[3] = new TextBox();
textbox_item_array[3].Width = label_item_quantity.Width;
textbox_item_array[3].Font = textbox_item_array[0].Font;
textbox_item_array[3].Location = new Point(label_item_quantity.Location.X, textbox_item_array[0].Location.Y);
textbox_item_array[3].Name = string.Concat("item_quantity", row_count.ToString());
panel_item_collections.Controls.Add(textbox_item_array[3]);
textbox_item_array[4] = new TextBox();
textbox_item_array[4].Width = label_item_total.Width;
textbox_item_array[4].Font = textbox_item_array[0].Font;
textbox_item_array[4].Location = new Point(label_item_total.Location.X, textbox_item_array[0].Location.Y);
textbox_item_array[4].Name = string.Concat("item_total", row_count.ToString());
panel_item_collections.Controls.Add(textbox_item_array[4]);
row_count++;
}
Now, here is the leave event handler:
void dynamic_text_item_code_Leave(object sender, EventArgs e)
{
//MessageBox.Show(((Control)sender).Name.Substring(((Control)sender).Name.Length - 1, 1));
int i;
string name_textbox = ((Control)sender).Name;
i = System.Convert.ToInt32(name_textbox.Substring(name_textbox.Length - 1, 1));
//MessageBox.Show(i.ToString());
//i--;
TextBox[] textbox_item_array = new TextBox[5];
textbox_item_array = (TextBox[])(item_textbox[i]);
double item_total;
Item item = new Item();
if (long.TryParse(textbox_item_array[0].Text, out item.item_code) == true)
{
if (item.get_item() == 0)
{
textbox_item_array[1].Text = item.item_details;
textbox_item_array[2].Text = item.sell_price.ToString();
textbox_item_array[3].Text = "1";
item_total = System.Convert.ToInt32(textbox_item_array[3].Text) * item.sell_price;
textbox_item_array[4].Text = item_total.ToString();
}
}
else
{
//TextBox[] textbox_item_array = new TextBox[5];
textbox_item_array = (TextBox[])(item_textbox[item_textbox.Count - 1]);
panel_item_collections.Controls.Remove(textbox_item_array[0]);
panel_item_collections.Controls.Remove(textbox_item_array[1]);
panel_item_collections.Controls.Remove(textbox_item_array[2]);
panel_item_collections.Controls.Remove(textbox_item_array[3]);
panel_item_collections.Controls.Remove(textbox_item_array[4]);
item_textbox.RemoveAt((item_textbox.Count - 1));
row_count--;
}
}
Now, the problem is like this:
If the user leave the textbox blank, the row will be deleted. The strange problem is:
If press tab, it will execute the leave event handler twice. It means it will try to delete the same textbox twice and this will create problem. Can any one help me how to avoid this double calling?
Thanks
I want to add more: here is exactly what is happening:
Now, I will give exactly how it is executed:
void dynamic_text_item_code_Leave(object sender, EventArgs e)
{
//MessageBox.Show(((Control)sender).Name.Substring(((Control)sender).Name.Length - 1, 1));
int i;
string name_textbox = ((Control)sender).Name;
i = System.Convert.ToInt32(name_textbox.Substring(name_textbox.Length - 1, 1));
//MessageBox.Show(i.ToString());
//i--;
TextBox[] textbox_item_array = new TextBox[5];
textbox_item_array = (TextBox[])(item_textbox[i]);
double item_total;
Item item = new Item();
if (long.TryParse(textbox_item_array[0].Text, out item.item_code) == true)
{
if (item.get_item() == 0)
{
textbox_item_array[1].Text = item.item_details;
textbox_item_array[2].Text = item.sell_price.ToString();
textbox_item_array[3].Text = "1";
item_total = System.Convert.ToInt32(textbox_item_array[3].Text) * item.sell_price;
textbox_item_array[4].Text = item_total.ToString();
}
}
else
{
//TextBox[] textbox_item_array = new TextBox[5];
textbox_item_array = (TextBox[])(item_textbox[item_textbox.Count - 1]);
panel_item_collections.Controls.Remove(textbox_item_array[0]);
After that, it calls the same function
void dynamic_text_item_code_Leave(object sender, EventArgs e)
{
//MessageBox.Show(((Control)sender).Name.Substring(((Control)sender).Name.Length - 1, 1));
int i;
string name_textbox = ((Control)sender).Name;
i = System.Convert.ToInt32(name_textbox.Substring(name_textbox.Length - 1, 1));
//MessageBox.Show(i.ToString());
//i--;
TextBox[] textbox_item_array = new TextBox[5];
textbox_item_array = (TextBox[])(item_textbox[i]);
double item_total;
Item item = new Item();
if (long.TryParse(textbox_item_array[0].Text, out item.item_code) == true)
{
if (item.get_item() == 0)
{
textbox_item_array[1].Text = item.item_details;
textbox_item_array[2].Text = item.sell_price.ToString();
textbox_item_array[3].Text = "1";
item_total = System.Convert.ToInt32(textbox_item_array[3].Text) * item.sell_price;
textbox_item_array[4].Text = item_total.ToString();
}
}
else
{
//TextBox[] textbox_item_array = new TextBox[5];
textbox_item_array = (TextBox[])(item_textbox[item_textbox.Count - 1]);
panel_item_collections.Controls.Remove(textbox_item_array[0]);
panel_item_collections.Controls.Remove(textbox_item_array[1]);
panel_item_collections.Controls.Remove(textbox_item_array[2]);
panel_item_collections.Controls.Remove(textbox_item_array[3]);
panel_item_collections.Controls.Remove(textbox_item_array[4]);
item_textbox.RemoveAt((item_textbox.Count - 1));
row_count--;
}
}
Then it continues here
panel_item_collections.Controls.Remove(textbox_item_array[1]);
panel_item_collections.Controls.Remove(textbox_item_array[2]);
panel_item_collections.Controls.Remove(textbox_item_array[3]);
panel_item_collections.Controls.Remove(textbox_item_array[4]);
item_textbox.RemoveAt((item_textbox.Count - 1));
row_count--;
}
}
So, why it executes once it get to the remove
Are you sure, you don't use this line twice in another part of code?
textbox_item_array[0].Leave += new EventHandler(dynamic_text_item_code_Leave);
If not I suppose you hooks dynamic_text_item_code_Leave to one another control.
EDIT
You can also to protect by adding this code:
if (textbox_item_array[0].Leave != null)
textbox_item_array[0].Leave += new EventHandler(dynamic_text_item_code_Leave);