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..?
Related
I'm trying to turn textboxes and buttons visible when the number of tracks it's selected in a combobox.
For example: when I select 3, just 3 textboxes and the 3 respective buttons to select the tracks are enabled. How can I change this code that I've made to a simple foreach or a for?
if (numero_faixas == 1) {
txtFaixa1.Visible = true;
btnFaixa1.Visible = true;
} else if (numero_faixas == 2) {
txtFaixa1.Visible = true;
btnFaixa1.Visible = true;
txtFaixa2.Visible = true;
btnFaixa2.Visible = true;
} else if (numero_faixas == 3) {
txtFaixa1.Visible = true;
btnFaixa1.Visible = true;
txtFaixa2.Visible = true;
btnFaixa2.Visible = true;
txtFaixa3.Visible = true;
btnFaixa3.Visible = true;
}
You can reduce the lines of code by changing your conditions, so you don't have to reference the same control so many times:
if (numero_faixas > 0)
{
txtFaixa1.Visible = true;
btnFaixa1.Visible = true;
}
if (numero_faixas > 1)
{
txtFaixa2.Visible = true;
btnFaixa2.Visible = true;
}
if (numero_faixas > 2)
{
txtFaixa3.Visible = true;
btnFaixa3.Visible = true;
}
To use a foreach loop, you could cast the Controls collection to an IEnumerable<Control> and then, using System.Linq;, you can filter on controls of type TextBox and Button, where the control name contains "Faxia". Then, in the loop body, we can use int.TryParse to try to convert the last character of the control name to an int, and if that succeeds, then set the control to Visible if the control number is less than numero_faixas + 1:
foreach (Control control in Controls.Cast<Control>()
.Where(c => (c is Button || c is TextBox) && c.Name.Contains("Faixa")))
{
// Get the number associated with this control and compare it to numero_faixas
int controlNumber;
if (int.TryParse(control.Name.Substring(control.Name.Length - 1), out controlNumber) &&
controlNumber < numero_faixas + 1)
{
control.Visible = true;
}
}
Here's a proof of concept that you could respin using your business rules.
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ShowHideButtons_47439046
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
InitOurThings();
}
private void InitOurThings()
{
//lets create a combo box with options to select
ComboBox combo = new ComboBox();
combo.Location = new Point(5, 5);//place it somewhere
//add selectable items
for (int i = 0; i < 10; i++)
{
combo.Items.Add(i);
}
combo.SelectedValueChanged += Combo_SelectedValueChanged;//the event which will handle the showing/hidding
Controls.Add(combo);//add the combo box to the form
//lets create some buttons and textboxes
int btnx = 5;
int btny = combo.Height + combo.Location.Y + 5;
for (int i = 0; i < 10; i++)
{
Button btn = new Button();
btn.Location = new Point(btnx, btny);
btn.Name = i.ToString();
btn.Text = i.ToString();
Controls.Add(btn);
btny += btn.Height + 5;
TextBox txtbx = new TextBox();
txtbx.Location = new Point(btn.Location.X + btn.Width + 5, btn.Location.Y);
txtbx.Name = i.ToString();
txtbx.Text = i.ToString();
Controls.Add(txtbx);
}
}
private void Combo_SelectedValueChanged(object sender, EventArgs e)
{
int selectedValue = int.Parse(((ComboBox)sender).SelectedItem.ToString());
foreach (Control item in Controls)
{
//show/hide the controls based on their Name being Equal Or Smaller than the selectedItem
if (item is TextBox)
{
int itemNumber = int.Parse(item.Name);
item.Visible = itemNumber <= selectedValue ? true : false;
}
if (item is Button)
{
int itemNumber = int.Parse(item.Name);
item.Visible = itemNumber <= selectedValue ? true : false;
}
}
}
}
}
C# TextBox
AutoCompleteCustomSource has a List<string>,
AutoCompleteMode = Suggest.
I can see the List when I type a Letter.
How to show entire list without Typing a Letter Programmatically? This must be done while the User presses the Down Arrow Key in the TextBox.
Is there any Win32 API Available?
My Solution
I refined a Better Solution.
Add a ListBox Control to the form and make it as Visible = false
int curSelIndex = -1;
The below given Code will be executed Form_Load Event.
txtEmpId.AutoCompleteCustomSource.AddRange(EmpIds.ToArray());
lstAutoComplete.Items.Clear();
lstAutoComplete.Items.AddRange(EmpIds.ToArray());
txtEmpId.KeyDown += (ks, ke) =>
{
if (!(ke.KeyCode == Keys.Down ||
ke.KeyCode == Keys.Up ||
ke.KeyCode == Keys.Enter))
{
lstAutoComplete.Visible = false;
return;
}
ke.Handled = true;
if (ke.KeyCode == Keys.Enter)
{
if (lstAutoComplete.Visible)
{
var str = lstAutoComplete.SelectedItem + "";
// Process the Selected Item and set to TextBox.
}
}
if (!lstAutoComplete.Visible && txtEmpId.Focused)
{
var loc = txtEmpId.Location;
loc.Y += txtEmpId.Height;
lstAutoComplete.Location = loc;
lstAutoComplete.Size = txtEmpId.Size;
lstAutoComplete.Height = 100;
lstAutoComplete.SelectedIndex = 0;
curSelIndex = 0;
lstAutoComplete.Visible = true;
}
else if(lstAutoComplete.Visible && txtEmpId.Focused)
{
if (ke.KeyCode == Keys.Down)
{
curSelIndex++;
if (curSelIndex >= lstAutoComplete.Items.Count)
curSelIndex = lstAutoComplete.Items.Count - 1;
if (lstAutoComplete.Items.Count > 0)
lstAutoComplete.SelectedIndex = curSelIndex;
}
else if (ke.KeyCode == Keys.Up)
{
curSelIndex--;
if (curSelIndex < 0)
curSelIndex = 0;
if (lstAutoComplete.Items.Count > 0)
lstAutoComplete.SelectedIndex = curSelIndex;
}
}
};
txtEmpId.Leave += (ls, le) => lstAutoComplete.Visible = false;
I didn't find any API for your problem, so I just make a my own suggestion box by using ListBox to show when the Down Arrow Key is pressed, when you do other operation, it disappeares. I hope it is useful to you. code sample is bellow:
//string datasource
List<string> strList = null;
//suggestion listbox
ListBox sugBox = null;
public FrmTextSuggest()
{
InitializeComponent();
//setting the textbox control
strList = new List<string>()
{
"USA",
"England",
"China",
"Japan",
"Korea",
"India",
"France",
"Canada"
};
var autoCollection = new AutoCompleteStringCollection();
autoCollection.AddRange(strList.ToArray());
this.txtCountry.AutoCompleteCustomSource = autoCollection;
this.txtCountry.AutoCompleteMode = AutoCompleteMode.Suggest;
this.txtCountry.AutoCompleteSource = AutoCompleteSource.CustomSource;
//register the Down Arrow Key event
this.txtCountry.KeyDown += new KeyEventHandler(txtCountry_KeyDown);
}
void txtCountry_KeyDown(object sender, KeyEventArgs e)
{
//show the your own suggestion box when pressing down arrow and the text box is empty
if (e.KeyCode == Keys.Down && txtCountry.Text.Trim().Equals(""))
{
sugBox = new ListBox();
//define the box
sugBox.Width = txtCountry.Width;
Point p = txtCountry.Location;
p.Y += txtCountry.Height;
sugBox.Location = p;
sugBox.Items.AddRange(strList.ToArray());
//copy the value to the textbox when selected index changed.
sugBox.SelectedIndexChanged += new EventHandler(sugBox_SelectedIndexChanged);
//show box
if (sugBox.Items.Count > 0)
{
sugBox.SelectedIndex = 0;
this.Controls.Add(sugBox);
sugBox.Focus();
}
}
//remove and hide your own suggestion box when other operation
else
{
if (sugBox != null && this.Controls.Contains(sugBox))
{
this.Controls.Remove(sugBox);
sugBox.Dispose();
sugBox = null;
}
}
}
void sugBox_SelectedIndexChanged(object sender, EventArgs e)
{
string selText = this.sugBox.SelectedItem.ToString();
if (!string.IsNullOrEmpty(selText))
{
this.txtCountry.Text = selText;
}
}
here is my result of test:
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.
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();
}
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);