C
C#14mo ago
Livid

❔ dictionary as datasource

if i do ...DataSource = dic.Values it works but it don't keep it updated when i add/remove value from the dictionary
19 Replies
Jimmacle
Jimmacle14mo ago
well, what does dic.Values give you?
Livid
LividOP14mo ago
the values
Jimmacle
Jimmacle14mo ago
i mean what type does it give you because it's not the same object as the dictionary
Livid
LividOP14mo ago
dic.Values does what i want but it don't keep updated
Jimmacle
Jimmacle14mo ago
...so it doesn't do what you want and i'm trying to help you learn why
Livid
LividOP14mo ago
....
Artikel artikel1 = new Artikel()
{
itemId = 1000000,
itemName = "article naam"
};
_artikelsList.Add(artikel1.itemId, artikel1);
grid.DataSource = _artikelsList.Values;
Artikel artikel2 = new Artikel()
{
itemId = 2000000,
itemName = "article naam"
};
_artikelsList.Add(artikel2.itemId, artikel2);
Artikel artikel1 = new Artikel()
{
itemId = 1000000,
itemName = "article naam"
};
_artikelsList.Add(artikel1.itemId, artikel1);
grid.DataSource = _artikelsList.Values;
Artikel artikel2 = new Artikel()
{
itemId = 2000000,
itemName = "article naam"
};
_artikelsList.Add(artikel2.itemId, artikel2);
value with key 200000 doesn't get added
Jimmacle
Jimmacle14mo ago
so what is the answer to my original question?
Livid
LividOP14mo ago
artikel
Jimmacle
Jimmacle14mo ago
try again
Livid
LividOP14mo ago
IDictionary<int, Artikel> _artikelsList = new Dictionary<int, Artikel>();
Jimmacle
Jimmacle14mo ago
that is not what _artikelsList.Values gives you
Livid
LividOP14mo ago
collection ?
Jimmacle
Jimmacle14mo ago
valuecollection but close enough winforms probably doesn't know how to understand when that is updated
Livid
LividOP14mo ago
so should i use a dictionary?
Jimmacle
Jimmacle14mo ago
if you look at the docs it explains what kinds of objects are supported for data binding https://learn.microsoft.com/en-us/dotnet/desktop/winforms/data/overview?view=netdesktop-7.0
Overview of Data Binding and Windows Forms - Windows Forms .NET
Learn about interfaces related to Data Binding, data sources supported by Windows Forms, and types of Data Binding.
Livid
LividOP14mo ago
bananas i want to insert list of article into another but i don't want duplicate value with id property article has a property id
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Livid
LividOP14mo ago
no
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server