Listview Remove Selected item*HELP*

  • Thread starter Thread starter Batista001
  • Start date Start date
B

Batista001

Guest
I need help knowing the selected item to remove at a method

the "lista" is created at the main form


namespace TrabalhoMod9
{
public partial class FormApagar : Form
{
int Encontrachave(List<Artigo> lista, int referenciachave)
{
for (int i = 0; i < lista.Count(); ++i)
if (lista.Referencia == referenciachave)
{
return i;
}
return -1;
}
private List<Artigo> list_apagar = null;
public FormApagar(List<Artigo> lista3)
{
InitializeComponent();
list_apagar = lista3;
}

private void BttApagar_Click(object sender, EventArgs e)
{
listViewApagar.
if (listViewApagar.SelectedItems.Count > 0)
{
string x = listViewApagar.SelectedItems[1].Tag.ToString();
if (Encontrachave(list_apagar, int.Parse(x)) ==-1)
{
MessageBox.Show("O Indice não existe");
}
else
{
int indselecionado = listViewApagar.SelectedIndices[0];
list_apagar.RemoveAt(indselecionado);
Encontrachave(list_apagar, int.Parse(x));
}


//listViewApagar.Items.RemoveAt();
}
}
private void FormApagar_Load(object sender, EventArgs e)
{
listViewApagar.View = View.Details;
listViewApagar.GridLines = true;
listViewApagar.MultiSelect = false;
listViewApagar.FullRowSelect = true;

listViewApagar.Columns.Add("Nome", 80, HorizontalAlignment.Center);
listViewApagar.Columns.Add("Referencia", 100, HorizontalAlignment.Center);
listViewApagar.Columns.Add("Preco", 100, HorizontalAlignment.Center);
listViewApagar.Columns.Add("Categoria", 100, HorizontalAlignment.Center);
foreach (Artigo x in list_apagar)
{
string[] linha = new string[4];
linha[0] = x.Nome;
linha[1] = x.Referencia.ToString();
linha[2] = x.Preco.ToString();
linha[3] = x.Categoria;
listViewApagar.Items.Add(new ListViewItem(linha));
}
}
}
}

Continue reading...
 

Similar threads

Back
Top