I am making an application that has some options in drop-down menus that get populated from the App.Config file. I was testing a reset function when the program stopped doing the reset. My code for Form1 is below:
public Form1()
{
InitializeComponent();
InitializeDropDownMenu();
}
private void InitializeDropDownMenu()
{
//Populate all the menus from app.config
foreach (string s in Properties.Settings.Default.Box1Contents)
{
comboBox1.Items.Add(s);
}
foreach (string s in Properties.Settings.Default.Box2Contents)
{
comboBox2.Items.Add(s);
}
foreach (string s in Properties.Settings.Default.Box3Contents)
{
comboBox3.Items.Add(s);
}
//Controls for drop down menus
this.Controls.Add(comboBox1);
comboBox1.SelectedIndexChanged +=
new System.EventHandler(comboBox1_SelectedIndexChanged);
this.Controls.Add(comboBox2);
comboBox2.SelectedIndexChanged +=
new System.EventHandler(comboBox2_SelectedIndexChanged);
this.Controls.Add(comboBox3);
comboBox3.SelectedIndexChanged +=
new System.EventHandler(comboBox3_SelectedIndexChanged);
//Begin Program with all dDMenus enabled.
comboBox1.Enabled = true;
comboBox2.Enabled = true;
comboBox3.Enabled = true;
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
DialogResult result = MessageBox.Show(
"Change Viewer to: \r\n" + comboBox1.Text + "\r\n\r\n" + "Confirm?",
"Menu",
MessageBoxButtons.YesNo,
MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
label3.Text = comboBox1.SelectedText;
}
else if( result == DialogResult.No)
{
comboBox1.ResetText();
}
}
private void comboBox2_SelectedIndexChanged(object sender, System.EventArgs e)
{
DialogResult result = MessageBox.Show(
"Change Viewer to: \r\n" + comboBox2.Text + "\r\n\r\n" + "Confirm?",
"Menu",
MessageBoxButtons.YesNo,
MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
label3.Text = comboBox2.SelectedText;
}
else if (result == DialogResult.No)
{
comboBox2.ResetText();
}
}
private void comboBox3_SelectedIndexChanged(object sender, System.EventArgs e)
{
DialogResult result = MessageBox.Show(
"Change Viewer to: \r\n" + comboBox3.Text + "\r\n\r\n" + "Confirm?",
"Menu",
MessageBoxButtons.YesNo,
MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
label3.Text = comboBox3.SelectedText;
}
else if (result == DialogResult.No)
{
comboBox3.ResetText();
}
}
private void ResetApp()
{
comboBox1.ResetText();
comboBox2.ResetText();
comboBox3.ResetText();
}
private void button1_Click(object sender, EventArgs e)
{
ResetApp();
label3.Text = "ResetApp Ran";
}
Any ideas as to why label3 is always set to null, and why when reset is clicked the ComboBoxes aren't being reset to blanks anymore?
Thank you for your help,
-Arthur
EDIT* I will use Items.Clear(); and then just call InitializeDropDownMenu() in the reset function. Should work for my intended use. Thank you all.
I think the problem is in use of SelectedText. The SelectedTextproperty "Gets or sets the text that is selected in the editable portion of a System.Windows.Forms.ComboBox".
Instead try to use the SelectedItem property.
label1.Text = comboBox1.SelectedItem.ToString();
Related
what I want to do is simple but I do not know how to do it. I'm doing a basic window login, and I wrote a code to ask for confirmation before exit, like this: (I have the names in spanish, the "Contador" is the counter if you do not understand)
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult dialogo = MessageBox.Show("¿Desea cerrar la aplicación?",
"Aviso!", MessageBoxButtons.YesNo, MessageBoxIcon.Hand);
if (dialogo == DialogResult.No)
{
e.Cancel = true;
}
}
What I've done after that, is a counter that if I entry the incorrect information three times, the application is going to close, here's the code:
private int Contador;
private void Form1_Load(object sender, EventArgs e)
{
Contador = 0;
aceptar.Enabled = false;
usuario.MaxLength = 40;
contraseña.MaxLength = 10;
}
private void aceptar_MouseClick(object sender, MouseEventArgs e)
{
if(Contador == 2)
{
DialogoCerrar();
Close();
}
if (usuario.Text == ("Demo") && (contraseña.Text == ("ABC123")))
{
Contador = 0;
DialogResult dialogo = MessageBox.Show(
"Ingreso exitoso!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
DialogResult dialogo = MessageBox.Show(
"Datos incorrectos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
Contador++;
}
}
So, this works, but when after three times I put the incorrect information, before to close the program ask me if I want to do it (I know that is for the Form1_FormClosing), and I want that the program doesn't ask it in that situation.
You just need to set a flag:
private bool _noConfirmExit;
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (_noConfirmExit)
{
return;
}
DialogResult dialogo = MessageBox.Show("¿Desea cerrar la aplicación?", "Aviso!", MessageBoxButtons.YesNo, MessageBoxIcon.Hand);
if (dialogo == DialogResult.No)
{
e.Cancel = true;
}
}
private void aceptar_MouseClick(object sender, MouseEventArgs e)
{
if(Contador == 2)
{
_noConfirmExit = true;
DialogoCerrar();
Close();
}
if (usuario.Text == ("Demo") && (contraseña.Text == ("ABC123")))
{
Contador = 0;
DialogResult dialogo = MessageBox.Show("Ingreso exitoso!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
DialogResult dialogo = MessageBox.Show("Datos incorrectos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
Contador++;
}
}
That way, your FormClosing event handler can tell the difference between closing for other reasons and closing because the counter reached its limit.
Here's code that tracks whether you should show the warning dialog box. It's basically a flag that you set when you don't want to show the dialog box.
public partial class Form1 : Form
{
private bool SkipWarning = false;
public Form1()
{
InitializeComponent();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if(!SkipWarning)
{
DialogResult dialogo = MessageBox.Show("¿Desea cerrar la aplicación?", "Aviso!", MessageBoxButtons.YesNo, MessageBoxIcon.Hand);
if (dialogo == DialogResult.No)
{
e.Cancel = true;
}
}
}
private void aceptar_MouseClick(object sender, MouseEventArgs e)
{
if(Contador == 2)
{
SkipWarning = true;
DialogoCerrar();
Close();
}
if (usuario.Text == ("Demo") && (contraseña.Text == ("ABC123")))
{
Contador = 0;
DialogResult dialogo = MessageBox.Show("Ingreso exitoso!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
DialogResult dialogo = MessageBox.Show("Datos incorrectos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
Contador++;
}
}
}
i have datagridview and column in it,and type is combobox.Combobox value's are used from sql data base.In combobox "Status" i have 5 different item value's.What i want is that when i change item value from combobox and press "save" button ,i want to check which value was before this one(before save) and say:
private void m02BindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
try
{
if (StatusTextBox.Text == "3" && // + want to ask here if previous statusTextBox.text was "1" then to execute lines down if not goes to 'else')
{
DialogResult mbox = MessageBox.Show("do you want to save today's date and time?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
datumOtvaranjaDateTimePicker.Focus();
if (mbox == DialogResult.Yes)
{
datumOtvaranjaDateTimePicker.Value = DateTime.Now;
}
Save();
Refresh();
}
else
{
MessageBox.Show("you cant do that!!!" + Environment.NewLine + "Check what you typed and try again", "Upozorenje", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Refresh();
}
}
catch (Exception)
{
}
}
Look at this other answer
You can handle the ComboBox.Enter event. Then save off the
SelectedItem or SelectedValue to a member variable
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
comboBox1.Enter += comboBox1_Enter;
}
private void comboBox1_Enter(object sender, EventArgs e)
{
m_cb1PrevVal = comboBox1.SelectedValue;
}
private void RestoreOldValue()
{
comboBox1.SelectedValue = m_cb1PrevVal;
}
}
I am programming in Visual Studio 2013, c# winform. Im trying to make something like Steam Library, but I don't know how to save FlowLayoutPanel that I have in tab1 (Library).
This is how it looks (Library)
This is how it looks (Adding a new game)
This is how it looks (Deleting a new game): http:// oi62.tinypic.com/2uzfc3k.jpg
(sorry, im not able to add images and more than 2 links)
Here is my code:
private void btnTest_Click_1(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
if (textBox2.Text != "")
{
if (textBox3.Text != "")
{
Button btn = sender as Button;
Button btnNew = new Button();
btnNew.Text = "";
btnNew.Height = 108;
btnNew.Width = 230;
btnNew.Name = textBox3.Text;
comboBox1.Items.Add(textBox3.Text);
btnNew.BackgroundImage = new Bitmap(textBox1.Text);
btnNew.BackgroundImageLayout = ImageLayout.Stretch;
btnNew.FlatStyle = FlatStyle.Flat;
flpContainer.Controls.Add(btnNew);
btnNew.Click += btnNew_Click;
btnNew.Tag = textBox2.Text;
counter1+=+1;
label1.Text = counter1.ToString();
System.Windows.Forms.MessageBox.Show("Game " + textBox3.Text + " was successfully added to library!");
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
else if (textBox3.Text == "")
{
MessageBox.Show("You didn't wrote name!");
}
}
else if (textBox2.Text == "")
{
System.Windows.Forms.MessageBox.Show("You didn't choose exe file!");
}
}
else if (textBox1.Text == "")
{
System.Windows.Forms.MessageBox.Show("You didn't choose image!");
}
}
private void btnNew_Click(object sender, EventArgs e)
{
Button clickedButton = (Button)sender;
Process.Start((string)clickedButton.Tag);
}
private void ZvolitObrazek_Click(object sender, EventArgs e)
{
openFileDialog1.Title = "Open Image";
openFileDialog1.FileName = "Image file";
openFileDialog1.Filter = "Image files (*.jpg, *.img, *.png, *.jpeg)|*.jpg; *.img; *.png; *.jpeg|All files (*.*)|*.*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = openFileDialog1.FileName;
}
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog2.Title = "Open exe";
openFileDialog2.FileName = "Exe file";
openFileDialog2.Filter = "Exe files (*.exe)|*.exe|All files(*.*)|*.*";
if (openFileDialog2.ShowDialog() == DialogResult.OK)
{
textBox2.Text = openFileDialog2.FileName;
}
}
private void flpContainer_Paint(object sender, PaintEventArgs e)
{
flpContainer.AutoScroll = true;
}
private void button2_Click(object sender, EventArgs e)
{
if (comboBox1.Text == "")
{
MessageBox.Show("You didn't choose game that you want delete!");
}
else if (comboBox1.Text != "")
{
Control foundControl = null;
foreach (Control c in flpContainer.Controls)
{
c.Name = comboBox1.Text;
foundControl = c;
}
flpContainer.Controls.Remove(foundControl);
counter1 = counter1 - 1;
label1.Text = counter1.ToString();
MessageBox.Show("Game " + comboBox1.Text + " was successfully deleted");
comboBox1.Items.Remove(comboBox1.Text);
comboBox1.Text = "";
}
}
}
FlowLayoutPanel=flpContainter.
So, my question is, how can i save items (buttons) in FlowLayoutPanel and how to load them later?
Thank you for your answers!
You should create a class for your items (game buttons), including their Title, Image etc. Then you can save them using XML.
class Game
{
// Properties here
}
This link will provide you with a quick How-to on how to accomplish this.
For saving images you can convert the image to base64 and convert it back to an image when loading the XML file again.
Maybe i got a better idea. This was the original code:
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private bool pause = false;
private bool cut1 = false;
private bool copy1 = false;
Form2 popup = new Form2();
public Form1()
{
InitializeComponent();
}
// The lines with performed actions of a file
private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
{
if (!pause)
{
listBox1.Items.Add("File Created> " + e.FullPath + " -Date:" + DateTime.Now);
}
}
private void fileSystemWatcher1_Changed(object sender, System.IO.FileSystemEventArgs e)
{
if (!pause)
{
listBox1.Items.Add("File Changed> " + e.FullPath + " -Date:" + DateTime.Now);
}
}
private void fileSystemWatcher1_Deleted(object sender, System.IO.FileSystemEventArgs e)
{
if (!pause)
{
listBox1.Items.Add("File Deleted> " + e.FullPath + " -Date:" + DateTime.Now);
}
}
private void fileSystemWatcher1_Renamed(object sender, System.IO.RenamedEventArgs e)
{
if (!pause)
{
listBox1.Items.Add("File Renamed> " + e.FullPath + " -Date:" + DateTime.Now);
}
}
private void fileSystemWatcher2_Changed(object sender, System.IO.FileSystemEventArgs e)
{
if (!pause)
{
listBox1.Items.Add("File Changed> " + e.FullPath + " -Date:" + DateTime.Now);
}
}
private void fileSystemWatcher2_Created(object sender, System.IO.FileSystemEventArgs e)
{
if (!pause)
{
listBox1.Items.Add("File Created> " + e.FullPath + " -Date:" + DateTime.Now);
}
}
private void fileSystemWatcher2_Deleted(object sender, System.IO.FileSystemEventArgs e)
{
if (!pause)
{
listBox1.Items.Add("File Deleted> " + e.FullPath + " -Date:" + DateTime.Now);
}
}
private void fileSystemWatcher2_Renamed(object sender, System.IO.RenamedEventArgs e)
{
if (!pause)
{
listBox1.Items.Add("File Renamed> " + e.FullPath + " -Date:" + DateTime.Now);
}
}
//1st directory
private void button2_Click(object sender, EventArgs e)
{
if (dlgOpenDir.ShowDialog() == DialogResult.OK)
{
fileSystemWatcher1.EnableRaisingEvents = false; // Stop watching
fileSystemWatcher1.IncludeSubdirectories = true;
fileSystemWatcher1.Path = dlgOpenDir.SelectedPath;
textBox1.Text = dlgOpenDir.SelectedPath; // Text of textBox2 = Path of fileSystemWatcher2
fileSystemWatcher1.EnableRaisingEvents = true; // Begin watching
}
}
//2nd directory
private void button3_Click(object sender, EventArgs e)
{
if (dlgOpenDir.ShowDialog() == DialogResult.OK)
{
fileSystemWatcher2.EnableRaisingEvents = false; // Stop watching
fileSystemWatcher2.IncludeSubdirectories = true;
fileSystemWatcher2.Path = dlgOpenDir.SelectedPath;
textBox2.Text = dlgOpenDir.SelectedPath; // Text of textBox2 = Path of fileSystemWatcher2
fileSystemWatcher2.EnableRaisingEvents = true; // Begin watching
}
}
//log
private void button1_Click(object sender, EventArgs e)
{
DialogResult resDialog = dlgSaveFile.ShowDialog();
if (resDialog.ToString() == "OK")
{
FileInfo fi = new FileInfo(dlgSaveFile.FileName);
StreamWriter sw = fi.CreateText();
foreach (string sItem in listBox1.Items)
{
sw.WriteLine(sItem);
}
sw.Close();
}
}
//pause watching
private void pause_button_Click(object sender, EventArgs e)
{
if (!pause)
{
pause = true;
pause_button.Text = "Unpause";
}
else
{
pause = false;
pause_button.Text = "Pause Watching";
}
}
//clear listbox
private void clear_button_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
}
private void Transfer_Click(object sender, EventArgs e)
{
//copy a file
if (copy1)
{
DialogResult dialogresult = popup.ShowDialog();
var source = FileBrowseBox.Text;
var target = Path.Combine(DestinationBox.Text, Path.ChangeExtension(FileNameBox.Text, Path.GetExtension(source)));
if (File.Exists(target))
{
if (dialogresult == DialogResult.OK)
{
File.Delete(target);
}
else if (dialogresult == DialogResult.Cancel)
{
}
}
else
{
File.Copy(FileBrowseBox.Text, Path.Combine(DestinationBox.Text, Path.ChangeExtension(FileNameBox.Text, Path.GetExtension(FileBrowseBox.Text))));
}
if (dialogresult == DialogResult.Cancel)
{
}
else
{
File.Copy(FileBrowseBox.Text, Path.Combine(DestinationBox.Text, Path.ChangeExtension(FileNameBox.Text, Path.GetExtension(FileBrowseBox.Text))));
}
}
//cut a file
if (cut1)
{
DialogResult dialogresult = popup.ShowDialog();
var source = FileBrowseBox.Text;
var target = Path.Combine(DestinationBox.Text, Path.ChangeExtension(FileNameBox.Text, Path.GetExtension(source)));
if (File.Exists(target))
{
if (dialogresult == DialogResult.OK)
{
File.Delete(target);
}
else if (dialogresult == DialogResult.Cancel)
{
}
}
else
{
File.Move(FileBrowseBox.Text, Path.Combine(DestinationBox.Text, Path.ChangeExtension(FileNameBox.Text, Path.GetExtension(FileBrowseBox.Text))));
}
if (dialogresult == DialogResult.Cancel)
{
}
else
{
File.Move(FileBrowseBox.Text, Path.Combine(DestinationBox.Text, Path.ChangeExtension(FileNameBox.Text, Path.GetExtension(FileBrowseBox.Text))));
}
}
}
private void Browse_file_Click(object sender, EventArgs e)
{
DialogResult resDialog = openFileDialog1.ShowDialog();
if (resDialog == DialogResult.OK)
{
FileBrowseBox.Text = openFileDialog1.FileName;
}
}
private void Browse_destination_Click(object sender, EventArgs e)
{
DialogResult resDialog = folderBrowserDialog1.ShowDialog();
if (resDialog == DialogResult.OK)
{
DestinationBox.Text = folderBrowserDialog1.SelectedPath;
}
}
private void CopyButton_CheckedChanged(object sender, EventArgs e)
{
copy1 = true;
}
private void Cut_CheckedChanged(object sender, EventArgs e)
{
cut1 = true;
}
}
}
I want the Filewatcher to watch the path of the FileBrowseBox, but with the FileBrowseBox you have to choose a file. How do i watch the path the file is in?
Is it possible that both copy1 and cut1 are true?
In your code you set the variables to true, regardless the state of the checkboxes.
Try to change the CheckedChanged-methods to
private void CopyButton_CheckedChanged(object sender, EventArgs e)
{
if (chkCopy.Checked)
{
copy1 = true;
cut1 = false;
// ToDo: Uncheck checkbox cut1
}
else
{
copy1 = false;
{
}
private void Cut_CheckedChanged(object sender, EventArgs e)
{
if (chkCut.Checked)
{
cut1 = true;
copy1 = false;
// ToDo: Uncheck checkbox copy1
}
else
{
cut1 = false;
{
}
Maybe it's more interesting to use radiobuttons instead of checkboxes?
When in the same group there can be only one checked while in your case both checkboxes can be checked.
Which make no sense since you can only copy or cut, not both at the same time.
I am working on selecting an item which will cause deletion of selected item. The problem is that when I delete an item I am selecting additional item which cause another deletion...
How do I unselest/deselect after deleting selected item?
This causes my problem:
void lbMessage_SelectedIndexChanged(object sender, EventArgs e)
{
DialogResult result = new DialogResult();
result = MessageBox.Show("Are you sure you want to remove this item?", "Removal Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
lbMessage.Items.Remove(lbMessage.SelectedItem);
lbMessage.SelectedIndex = -1;
}
else
{
}
}
private void btnAddMessage_Click(object sender, EventArgs e)
{
lbMessage.Items.Add(txtMessage.Text);
txtMessage.Text = string.Empty;
}
Try removing the SelectedIndexChanged event before removing the item, then add it back in:
private void lbMessage_SelectedIndexChanged(object sender, EventArgs e) {
if (MessageBox.Show("Are you sure you want to remove this item?",
"Remove Confirmation",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes) {
lbMessage.SelectedIndexChanged -= lbMessage_SelectedIndexChanged;
lbMessage.Items.Remove(lbMessage.SelectedItem);
lbMessage.SelectedIndexChanged += lbMessage_SelectedIndexChanged;
}
}
Setting SelectedIndex = -1 is raising the SelectedIndexChanged event. Check if there is nothing selected at the start of the event.
void lbMessage_SelectedIndexChanged(object sender, EventArgs e)
{
if (lbMessage.SelectedIndex == -1) return;
...
}
If you like it that way without a delete button then just do this:
bool isAfterDelete = false;
void lbMessage_SelectedIndexChanged(object sender, EventArgs e)
{
if (isAfterDelete)
{
isAfterDelete = false;
return;
}
DialogResult result = new DialogResult();
result = MessageBox.Show("Are you sure you want to remove this item?",
"Removal Confirmation",
MessageBoxButtons.YesNo,
MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
lbMessage.Items.Remove(lbMessage.SelectedItem);
isAfterDelete = true;
lbMessage.SelectedIndex = -1;
}
else
{
}
}
What if you just either wrap your code an in if() that checks for lbMessage.SelectedIndex == -1, or write a check for it at the beginning and return if it's true:
void lbMessage_SelectedIndexChanged(object sender, EventArgs e)
{
if(lbMessage.SelectedIndex == -1)
return;
DialogResult result = new DialogResult();
result = MessageBox.Show("Are you sure you want to remove this item?", "Removal Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
lbMessage.Items.Remove(lbMessage.SelectedItem);
lbMessage.SelectedIndex = -1;
}
}
The shear act of removing the item from the Items collection causes the items to change their index. This thus calls the "SelectedIndexChanged" event again on the list box. To prevent this, you would need to set a flag before the remove function to indicate that the SelectedIndexChange is being called after the
remove and prevent the event from occuring. You can do that by the following.
private bool afterRemove = false;
void lbMessage_SelectedIndexChanged(object sender, EventArgs e)
{
if (afterRemove)
{
afterRemove = false;
return;
}
DialogResult result = new DialogResult();
result = MessageBox.Show("Are you sure you want to remove this item?", "Removal Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
afterRemove = true;
lbMessage.Items.Remove(lbMessage.SelectedItem);
// Another call to "lbMessage_SelectedIndexChanged" is made right here.
}
}
private void btnAddMessage_Click(object sender, EventArgs e)
{
lbMessage.Items.Add(txtMessage.Text);
txtMessage.Text = string.Empty;
}
An alternative that might be easier to understand could be the following.
private bool afterRemove = false;
void lbMessage_SelectedIndexChanged(object sender, EventArgs e)
{
if (afterRemove)
return;
DialogResult result = new DialogResult();
result = MessageBox.Show("Are you sure you want to remove this item?", "Removal Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
afterRemove = true;
lbMessage.Items.Remove(lbMessage.SelectedItem);
// Another call to "lbMessage_SelectedIndexChanged" is made right here.
afterRemove = false;
}
}