Selecting a value from a Listview row/column populated by LINQ to SQL

Asked

Viewed 2,252 times

7

Through the double click event I need to pull a value from a row/column in a Listvview populated by LINQ to SQL.

For example, when the user needs to select a value from a row/column of this Listview, after the double click event, this information would feed a Textbox with the SQL database ID (not the Listview Index) corresponding to that row/column clicked.

Watch of can help me! Please!

Class that updates the List..

namespace TRSSystem.AcessoDados

public static List<tabProduto> Consultar_ALL()
        {
            TRSSystemDataClassesDataContext oDB = new TRSSystemDataClassesDataContext();
            List<tabProduto> oProdutos = (from Selecao in oDB.tabProdutos orderby Selecao.Descricao select Selecao).ToList<tabProduto>();
            return oProdutos;

    }

When I Start WPF Form...

listView_tabProduto.ItemsSource = TRSSystem.AcessoDados.tabProdutoAcesso.Consultar_ALL();

Event of the Double Click... (DOESN’T WORK)

private void Select_Item(object sender, MouseButtonEventArgs e)
        {


           txtDescricao.Text = listView_tabProduto.SelectedIndex.ToString(); -------> Não funciona

        }
  • Do you want the ID or index of the selected item? if it is the index you can do using: ListView1.SelectedIndex;

  • I am wanting to pull the line ID the user will click on the Listview that was loaded by LINQ...

  • Selectedindex, I can get the position in Listview... But I wanted to get the position in the Database (ID), not in Listview... You see?

  • yes I understand. I can see the code you use to popular the Listview ?

  • suggest edit your post and add code

  • Edited... I can understand?

Show 1 more comment

2 answers

1

1

  • While this link may answer the question, it is best to include the essential parts of the answer here and provide the link for reference. Replies per link only can be invalidated if the page with the link is changed. - From Review

  • Solved, this is it?

  • Opa now improved! When response is too short or just has link it falls in the analysis queue, that first comment is automatic.

  • I get it, thank you!

  • It still hasn’t worked with the old pole... The error: An unhandled Exception of type 'System.Nullreferenceexception' occurred in Trssystem.exe Additional information: Undefined object reference for an instance of an object. I believe you are not pulling the value of the row clicked with the "Description" column... Value is null... Any other suitability!? Att.

Browser other questions tagged

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