How to Restrict the List to other class property?

prabha_friend

Prabhakaran Karuppaih
Local time
Today, 05:49
Joined
Mar 22, 2009
Messages
872
Code:
Imports Microsoft.VisualBasic

Public Class Vegetable
    Dim NameVal As String
    Property Name() As String
        Get
            Return NameVal
        End Get
        Set(value As String)
            NameVal = value
        End Set
    End Property
End Class

Code:
Imports Microsoft.VisualBasic
Public Class Vendor
    Public ListOfVeggies As New List(Of Vegetable)
    Dim Vendor_Name As String
    Public Property Name() As String
        Get
            Return Vendor_Name
        End Get
        Set(value As String)
            Vendor_Name = value
        End Set
    End Property
    Public Sub AddVegetable(ByVal Vegetable1 As Vegetable)
        ListOfVeggies.Add(Vegetable1)
    End Sub
    Public ReadOnly Property VeggiesHandling() As List(Of Vegetable)
        Get
            Return ListOfVeggies
        End Get
    End Property
End Class

Code:
Imports Microsoft.VisualBasic

Public Class Bill
    Dim Bill_Vendor As New Vendor
    Public Property Vendor() As Vendor
        Get
            Return Bill_Vendor
        End Get
        Set(value As Vendor)
            Bill_Vendor = value
        End Set
    End Property
    Dim BilledVeggies As New List(Of Vegetable)
    Dim Billed_Qty As New List(Of Double)
    Dim Bill_Amount As New List(Of Double)
    Public Sub AddToBill(ByVal Vegetable1 As Vegetable, ByVal Qty As Double, ByVal Price As Double)
        BilledVeggies.Add(Vegetable1)
        Billed_Qty.Add(Qty)
        Bill_Amount.Add(Price)
    End Sub
End Class

Code:
Imports System
Imports System.Reflection.Metadata.Ecma335
Imports System.Security.Cryptography.X509Certificates

Module Program
    Public Sub Main()
        Dim Tomato As New Vegetable
        With Tomato
            .Name = "TomatoNadu"
        End With
        Dim Onion As New Vegetable
        With Onion
            .Name = "Onion Big"
        End With
        Dim Chilly As New Vegetable
        With Chilly
            .Name = "Chilly"
        End With
        Dim Ginger As New Vegetable
        With Ginger
            .Name = "Ginger"
        End With
        Dim Garlic As New Vegetable
        With Garlic
            .Name = "Garlic"
        End With
        Dim MGM As New Vendor
        With MGM
            .Name = "MGM"
            .AddVegetable(Tomato)
        End With
        Dim NSR As New Vendor
        With NSR
            .Name = "NSR Vegetables"
            .AddVegetable(Chilly)
            .AddVegetable(Onion)
            .AddVegetable(Garlic)
        End With
        Dim Bill1 As Bill
        With Bill1
            .Vendor = MGM
            .AddToBill()
        End With
        Dim Althaf As New Restaurant
        With Althaf
            .Name = "Althaf Restaurant"
            .Shipping = 50
        End With
        Dim Sathars As New Restaurant
        With Sathars
            .Name = "Sathar's"
        End With
        Dim Sivas As New Restaurant
        With Sivas
            .Name = "Sivas Restaurant"
            .Shipping = 80
        End With
        Dim Invoice1 As New Invoice
        With Invoice1
            .Restaurant = Althaf
            .AddVegetable(Tomato, 3)
            .AddVegetable(Onion, 2)
            .AddVegetable(Chilly, 0.5)
            .AddVegetable(Ginger, 0.25)
        End With
        Console.Write(Invoice1.Invoice_Amount)
    End Sub
End Module
Currently Bill.AddToBill() is listing out all the vegetables but I want to list only the VeggiesHandled by that Vendor. How to do? Thanks :)
 

Attachments

List where? In a dropdown?
What you describe is known as cascading or dependent combobox/listbox. A very common topic.
 
I don't understand that statement.

I have no idea how you would code this in your app with VB.

In Access VBA it would be setting the RowSource property of a combobox or listbox.
 
I think you want to add one object to the bill. If you look at this code...
Code:
Public Sub AddToBill(ByVal Vegetable1 As Vegetable, ByVal Qty As Double, ByVal Price As Double)
    BilledVeggies.Add(Vegetable1)
    Billed_Qty.Add(Qty)
    Bill_Amount.Add(Price)
End Sub
See how you are adding three distinct things? This should be one object, roughly corresponding to one row in a table. This is what I was saying in your other thread about learning C#. The hard part is understanding how to structure your classes. Generally, I would expect your data classes to have pretty close correspondence to your tables, since that is the structure of your problem. So one row in a table would likely have a class type with a similar name, representing the distinct instance of something, whatever that table row represents.
But this is just your data layer. These are the "Model"s in your Model/View/ViewModel pattern.

Also, it is handy to give your classes constructors, so consider...
Code:
Public Class Vegetable
    Dim _name As String
    
    Sub New(Name as String)
        _name = Name
    End Sub
    
    ReadOnly Property Name() As String
        Get
            Return _name
        End Get
    End Property
End Class
Then you can do...
Code:
        Dim Tomato As New Vegetable("Tomato")
        Dim Onion As New Vegetable("Onion, Large")
        Dim Chilly As New Vegetable("Chilli")
        Dim Ginger As New Vegetable("Ginger")
 
I think you want to add one object to the bill. If you look at this code...
Code:
Public Sub AddToBill(ByVal Vegetable1 As Vegetable, ByVal Qty As Double, ByVal Price As Double)
    BilledVeggies.Add(Vegetable1)
    Billed_Qty.Add(Qty)
    Bill_Amount.Add(Price)
End Sub
See how you are adding three distinct things? This should be one object, roughly corresponding to one row in a table. This is what I was saying in your other thread about learning C#. The hard part is understanding how to structure your classes. Generally, I would expect your data classes to have pretty close correspondence to your tables, since that is the structure of your problem. So one row in a table would likely have a class type with a similar name, representing the distinct instance of something, whatever that table row represents.
But this is just your data layer. These are the "Model"s in your Model/View/ViewModel pattern.

Also, it is handy to give your classes constructors, so consider...
Code:
Public Class Vegetable
    Dim _name As String
   
    Sub New(Name as String)
        _name = Name
    End Sub
   
    ReadOnly Property Name() As String
        Get
            Return _name
        End Get
    End Property
End Class
Then you can do...
Code:
        Dim Tomato As New Vegetable("Tomato")
        Dim Onion As New Vegetable("Onion, Large")
        Dim Chilly As New Vegetable("Chilli")
        Dim Ginger As New Vegetable("Ginger")
In the below picture all veggies are listed. But as the Vendor is MGM. I want only Tomato to be listed. Possible?
Veggies_List.png
 

Users who are viewing this thread

Back
Top Bottom