C
C#5mo ago
Nebula

✅ BindingList<T> ???

Context: Hello, I'm working through my first C# class (which happens to be at the end of my degree program) and I've been recommended by my project instructions to use a binding list. The problem comes with my class having relatively poor material so I've learned just about everything through a Udemy course. The course didn't specifically cover .NET Framework / Window Form apps spefically so I'm having a couple hiccups in that aspect. I read through Microsoft's docs on BindingList but still don't really grasp what it does / it's use case. Additonally, I haven't been able to find anything other than AI content on YouTube. I'll be using BindingList to implement several items that will be compiled into an inventory system being displayed in the form of a datatable. Question: Would anyone be able to hop in a call and explain the basics of BindingList?
51 Replies
leowest
leowest5mo ago
well your context doesn't really tell us much about what your app have, bindinglist is used in specific scenarios BindingList is often used with say ListBox or DataGrid or ListView to provide an easy binding between the code behind and data present and automating notifications to the UI so when you insert an item to your binding list it updates your actual list in the application without the need of manually doing things around whether u should or not use a bindinglist as opposed to say a datatable it will vastly depend on your app needs as well
Nebula
NebulaOP5mo ago
I updated to answer my implementation as best as I can. I've been given my overall class structure and it seems like it's to have several properties as I believe they will all need to be updated together in a single datatable wihtin a given form.
leowest
leowest5mo ago
are you using Ado? or an ORM
Nebula
NebulaOP5mo ago
This is my first time working with A: multi-form solutions and B: with updating any form element more complex than a label. The Udemy course I've been following has been focusing mainly on specific things (i.e. properties vs fields, sealed classes, ect) but it's been explaining everything through a console app.
leowest
leowest5mo ago
I misread datatable as database 😛 so normally imagine you have a DataGrid
Nebula
NebulaOP5mo ago
I'm not familar with what Ado / ORM are, however I don't believe so. This is a pretty bare bones solution all things considered.
leowest
leowest5mo ago
you would use an adapter to populate the datatable and use that to set the datagrid datasource so are you not using an actual database? MSSQL, PostgreSQL etc?
Nebula
NebulaOP5mo ago
I don't have a data grid. I have no idea how to make a datatable using windows forms but I was gonna figure that out when I got there lmao. I was getting pretty overwhelemed. For now I have a TableLayoutPanel with Panels inside but I have no idea if it'll work. I was gonna try and get most of my classes working before updating any forms. I might be calling an API but nothing more than that. I haven't easily been able to find any API they want me to call yet, but I also havent gotten to the step of implementing it.
leowest
leowest5mo ago
yeah I am pretty lost on what u have and what you're trying to do then since u have not provided anything about your app or your code
Nebula
NebulaOP5mo ago
But I wont be usiung anything like MSSQL, no.
leowest
leowest5mo ago
but sure imagine I have a ListBox or ListView I can call an API, fill a BindingList<T> and that will auto update my ListBox/ListView
Nebula
NebulaOP5mo ago
Pretty much I have a few pictures showing what they want the GUI it look like, and I have a class structure that tells me what names and types proporties and methods are supposed to be. The diagram also shows how the classes are relient on each other. I think this is why I'm so lost on what a BindingList is / why to use it. I didn't come up with deciding for this proporty to be a BindingList I was just told to do so.
Nebula
NebulaOP5mo ago
A ListBox is just a form element right? yeah I just checked
leowest
leowest5mo ago
yes listbox is a winform element that lets u add multiple items to it
Nebula
NebulaOP5mo ago
Sweet
leowest
leowest5mo ago
can u provide some of the images of what the app is supposed to look like?
Nebula
NebulaOP5mo ago
Is a BindingList essentially jsut a List that updates an element when an item inside of it is changed? yeah
leowest
leowest5mo ago
the good part of the BindingList is how easy it allows you to bind business logic to update the ui without much complexity
Nebula
NebulaOP5mo ago
No description
leowest
leowest5mo ago
that looks more like a DataGrid
Nebula
NebulaOP5mo ago
And this is my super rough not formatted idea I've made:
Nebula
NebulaOP5mo ago
No description
leowest
leowest5mo ago
nah parts and products are just a DataGrid so u would use a datatable instead
Nebula
NebulaOP5mo ago
What element do I use to make datatables with?
leowest
leowest5mo ago
DataGrid is the winform control
Nebula
NebulaOP5mo ago
Currently I'm using a TableLayouPanel with Panels inside but I doubt thats the best way
leowest
leowest5mo ago
DataTable is the type that u populate its datasource althou u might be able to use a BindingList too never tried no that is not they serve to a different purpose and they are not as complex as a DataGrid is
Nebula
NebulaOP5mo ago
figured lmao Youtubeing "how to make a datatable in windows form" didn't get me anywhere that adds up to why it was so hard to get it to look even the way it does in my second pic
Nebula
NebulaOP5mo ago
is DataGridVeiw the same thing as DataGrid here?
leowest
leowest5mo ago
yeah sorry many years not using winforms, DataGridView
Nebula
NebulaOP5mo ago
all good
leowest
leowest5mo ago
the only difference from the example in the link above
Nebula
NebulaOP5mo ago
and I have zero expierence using DataBinding but I know there is a ton of videos on that I can check out, kept popping up when I was searching for BindingList
leowest
leowest5mo ago
is that instead of using dataAdapter and Sql u will populate the DataTable yourself since it comes from an API
Nebula
NebulaOP5mo ago
So since I'm not using an actual database I have enter manually either way and this is the method to do so If I'm understanding it correctly, BindingList is essentially a List that I'm able to use binding data with and bind said data to my DataGrid?
leowest
leowest5mo ago
here is an example of the first link I sent u but instead of a listbox it uses a bindinglist https://learn.microsoft.com/en-us/answers/questions/1345418/datagridview-bindinglist-propertychanged yes BindingList is responsible for notifying the ui of changes done to the objects inside and the list it self and viceversa so if u add an item to the bindlist it shows on the datagrid if u modify that item on the datagrid it updates the object in the bindinglist
Nebula
NebulaOP5mo ago
is it kinda like having an event built into a list object?
leowest
leowest5mo ago
sure u could say that
Nebula
NebulaOP5mo ago
maybe not under the hood but logically functions in that sort of way
leowest
leowest5mo ago
I mean that is what it does under the hood its just very complex bloat of reflection and what not
Nebula
NebulaOP5mo ago
I think I've got enough to get some serious work done in this project. I'll go ahead and mark this as resolved. Is it cool if I send you a DM if I run something else I can't figure out or should I just make a new post here?
leowest
leowest5mo ago
I dont take dms
Nebula
NebulaOP5mo ago
Also how would I go about marking this as resolved
leowest
leowest5mo ago
if u need help open a new help thread $closer
Nebula
NebulaOP5mo ago
All good
leowest
leowest5mo ago
$close
MODiX
MODiX5mo ago
If you have no further questions, please use /close to mark the forum thread as answered
leowest
leowest5mo ago
pretty much all help happens in either one of the help channels or here as a thread
Nebula
NebulaOP5mo ago
I really appreciate the help, thank you! Awesome! Makes sense to me
Want results from more Discord servers?
Add your server