Question list with methods

paulthepaddy

Well-known member
Joined
Apr 9, 2011
Messages
222
Location
UK
Programming Experience
Beginner
hi guys this sit eh code im using

Dim Car_Select As New List(Of ExecutableItem)
this is declaired in the form class, not in any event or sub

this is in the form load event, which works the combobox does get the car 1 added
VB.NET:
Car_Select.Add(New ExecutableItem With {.Text = "Car 1", .Method = AddressOf View_car1})
        With ComboBox1
            .DisplayMember = "Text"
            .ValueMember = "method"
            .DataSource = Car_Select
        End With

this is in a button click event But it wont add car 2 to the combobox
VB.NET:
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_Finish.Click
        If car1.finished = False Then
            car1.Make = ComboBox_Car_Maker.Text
            car1.Model = ComboBox_Car_Model.Text
            car1.Colour = ComboBox_Car_Colour.Text
            car1.Reg = StrConv(TXT_Car_reg.Text, VbStrConv.Uppercase)
            car1.Subtotal = Car_Price_Subtotal.Value
            If CheckBox_Discount.Checked = True Then
                car1.Discount = SSR_add_Minus.Value
                car1.additional = 0
            Else
                car1.Discount = 0
                car1.additional = SSR_add_Minus.Value
            End If
            car1.Total = Car_Price_Total.Value
            car1.finished = True

            Car_Select.Add(New ExecutableItem With {.Text = "Car 2", .Method = AddressOf View_Car2})
            With ComboBox1
                .DisplayMember = "Text"
                .ValueMember = "method"
                .DataSource = Car_Select
            End With
            Call clear_car_Details()
            Exit Sub
it does pass the if statement as the clear_Car_Details does get called
 
First up, don't bind the control again. The ComboBox is already bound to the List, so you don't have to do that again.

That said, your issue is that the List(Of T) class was not built with binding in mind, so it provides no notification to the bound control to update when the list changes. You have two options:

1. Use a BindingList instead of a List. It has methods such as ResetBindings that you can call after making a change to the list that will notify the bound control that it should update.

2. Bind the List to a BindingSource and bind that to the control. It also has methods such as ResetBindings for the same purpose.
 
thanks for the reply, and sory it took me a while to get back to you, i was waiing on an email saying i had a reply.. it never came lol.

how do i create a binding list instead of a list???

do i do it when i am creating the object
Dim Car_Select As New List(Of ExecutableItem)

or is it something i do when creating the class
 
If I said that you should use a String instead of an Integer, you'd know what to do right? This is the same. Currently you are creating a List(Of T). Create a BindingList(Of T) instead.
 
lol i would know what to do when changing from string to integer, but nothing is coming up with binding
i have tried the following

Dim Car_Select As New List(Of ExecutableItem)
Dim Car_Select As New Binding(Of ExecutableItem)
Dim Car_Select As New Bindinglist(Of ExecutableItem)
Dim Car_Select As New ListBindingConverter(Of ExecutableItem)

so is their something else i have to do??? like an import or a referance

sorry if this seems like a silly question, but everything i know about VB.NET is self taught or learnt from people on this forum.

my best learning method is to be shown what to do and then i do it a few times myself.
 
thank you got it working with the rest of my code, and it is working how i wanted it, BTW i didn't have to use Car_Select.ResetBindings() it is refreshing the list it's self thanks for the help :D
 
Back
Top