简体   繁体   中英

Displaying BindingList<(int, int, int)> in DataGridView

I have a BindingList that is as follows:

var lst = BindingList<(int Count, int ProductId, int SupplierId)>

and I am trying to display this list in a DataGridView :

dataGridView1.DataSource = lst;

lst contains a few elements and I can see the DataSource is being set properly when looking in the debugger. However, nothing is showing up in dataGridView1 . From the research I've done, I think this issue is related to not having any columns. I set AutoGenerateColumns to true , but this still did not resolve this issue.

I had assumed the names of each tuple item would be taken as the column name, but now it seems that is not the case. How do I display this BindingList in a DataGridView such that each tuple item is in its own column?

You can not use value tuples in data-binding, because tuples implemented by using "fields", where Winforms data-binding works with properties.

In your particular case you should create a class with properties.

public class Line
{
    public int Count { get; set; }

    public int ProductId { get; set; }

    public int SupplierId { get; set; }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM