How does listview insert a picture under C
- 2021-10-11 19:24:49
- OfStack
How to insert pictures in listview, I believe you would like to know, let's share the specific steps for you:
Step 1: Drag ListView and imageList controls into the form;
Step 2: Set the Images property of the imageList control and add the picture you want;
Step 3: Set the SmallImageList, LargeImageList, StateImageList properties of the ListView control to imageList;
Step 4: Edit the ImageIndex behavior of the ListView control item and you will find that the image is displayed successfully!
Attachment: Code for adding options to ListView controls
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show(" Added content cannot be empty ");
textBox1.Focus(); // Get the focus
}
else
{
if (listView1.Items.Count > 0) // Determine whether there are items in the list box
{
// Loop to compare whether there are duplicates, and abandon adding if there are duplicates
for (int i = 0; i < listView1.Items.Count; i++)
{
if (string.Compare(listView1.Items[i].Text.ToString(), textBox1.Text) == 0)
{
MessageBox.Show(" Items are duplicate and cannot be added! ");
textBox1.Text = ""; // Empty the text box
textBox1.Focus();
return;
}
}
listView1.Items.Add(textBox1.Text.ToString());
textBox1.Text = "";
}
else
{
listView1.Items.Add(textBox1.Text.ToString()); // Add data from a text box to a list box
textBox1.Text = "";
}
}
}
The above is the whole content of this article, I hope this article is helpful for everyone to learn C # programming.