Manipulating Listview C#

Asked

Viewed 741 times

2

I have a Listview that displays the data on the screen and has several rows and columns. For example:

      Cl1 | Cl2 | Cl3
  L1  aa  | bb   |  cc
  L2  ab  | bc   |  cd
  L3  ac  | bd   |  ce

I wonder, if you have any c# native functions (like: lambda, LINQ, etc), to search and change values in Listview? For example: Search for ab (Cl1,L2), and change cd (Cl3, L2) to'test'.

1 answer

3


In theory you can extract Items and make it a list:

var lista = minhaListView.Items;

Then you can search like this:

var elemento = lista.FirstOrDefault(l => l.nome == "Fulano");

Altering:

elemento.nome = "Beltrano";

Or to access a certain line (consider that for the list the position 0 is the first element):

var elementoNaTerceiraLinha = minhaListView.Items[2];
  • But, as I will know, what is the corresponding line of Listview, which is on elemento? Because, in this variable you only took an instance of minhaListView.

  • @Diegomoreno I updated the answer. See if it fits you.

  • Was of great use.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.