Hi guys I have the following ListView
:
This ListView has 3 columns in the second placed the URLs using a button containing this code:
ListViewItem listViewItem= new ListViewItem();
String url = textBox1.Text;
listViewItem.SubItems.Add(url);
listViewItem.Name = url;
listView1.Items.Add(listViewItem);
and the third column is left empty; once hydrated ListView
with the URL and Status columns; I have added a button to validate these URLS which has the following code:
private void button5_Click(object sender, EventArgs e)
{
PictureBox picture = new PictureBox
{
SizeMode = PictureBoxSizeMode.StretchImage,
BorderStyle = BorderStyle.None,
};
foreach (ListViewItem eachItem in listView1.Items)
{
if (webRequestManager.ValidateURL(eachItem.Name))
{
picture.Image = Properties.Resources.correct;
}
else
{
picture.Image = Properties.Resources.incorrect;
}
//Aqui no se que poner para que la columna status en el row especifico se Actualice y agregue el pitcute box.
}
}
As you can see, once I have generated the picture box, I don't know how to inject it into the status column of each row.
I have already searched the site and these suggested posts do not achieve or contribute to solving my scenario:
Position yourself in a specific column and row
How to pass image from ListView to a pictureBox?
This is more or less the expected result:
update
I have implemented an ImageList:
private void button5_Click(object sender, EventArgs e)
{
ImageList imagenes = new ImageList
{
ImageSize = new Size(16, 16),
ColorDepth = ColorDepth.Depth8Bit
};
imagenes.Images.Add(Properties.Resources.correct);
imagenes.Images.Add(Properties.Resources.incorrect);
listView1.SmallImageList = imagenes;
foreach (ListViewItem eachItem in listView1.Items)
{
if (webRequestManager.ValidateURL(eachItem.Name))
{
listView1.Items[eachItem.Index].ImageIndex = 1;
}
else
{
listView1.Items[eachItem.Index].ImageIndex = 0;
}
}
}
But I have not been able to make the image appear in column #3 of status:
In order to put an image in a column you must make use of the ImageList component . As its name indicates, this control saves a collection of images that can be used in other controls such as the ListView .
Once you insert the ImageList control you go to its Images property and create a collection of images (insert as many images as you want). This ImageList control gives an index to each image in its image collection, thus guaranteeing easy access to any image by the index you indicate (just like with an array).
So to give an image to any column of the ListView you would do:
We tell the first record of the ListView to put the first image saved in the ImagaList component in the column you want .
Check this well and adapt it to your needs.
Update Adaptation Made: