Click here to Skip to main content
15,615,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to get data from datagridview to a list and i refer to the list as a shopping Cart. am using a buttonColumn inoder to get the data. The columns am targeting are ProductName and price i have tried a few ways but am having erros like this "Object reference not set to an instance of an object." i cant what exactly am missing please enlighten me

What I have tried:

private void ViewSearchData_CellContentClick(object sender, DataGridViewCellEventArgs e)
          List<Items> Cart;

           if (e.ColumnIndex==ViewSearchData.Columns["SELECTED"].Index)


              String name = ViewSearchData.Rows[e.RowIndex].Cells["name"].Value.ToString();
              int price = (int)(ViewSearchData.Rows[e.RowIndex].Cells["price"].Value);
              Items item = new Items(name, price);
              Cart = new List<Items>();

Updated 18-Jan-23 18:26pm

1 solution

I did a quick Google Search for a quick answer: wpf datagridview edit button not working - Google Search[^] and found the following (code-behind method): Get current row when edit button clicked in WPF DataGrid?[^]

But, if you are doing MVVM, then this google search: wpf datagridview edit button not working mvvm - Google Search[^] and found the following: Firing a RelayCommand from a button inside a WPF DataGrid[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900