Listview in VB.NET - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Listview in VB.NET

softtips2004softtips2004 Posts: 6Member
I have a tab control in my winform and i have to display a listview with the same set of data loaded in all the tab pages.Do i have to use inheritance or call a procedure?

Comments

  • VCGVCG Posts: 51Member
    Actually, there is nothing you should do. if you are using Data Binding to controls, then All the control within that form will be bound altogether. ----- as one pointer change, it is reflected to the other bound controls as well. I don't think there's need for inheritance here. All that is required is, you bind your controls to the same dataset and you're done.

    And if, you are not working on database, for example you're working on Variables or Constants, a simpler way is put all the Collection in a Module as an array, and if you need to refer to those collection, rather than putting it in all of your controls item collection, create a Sub procedure to load all those data into your Control. If you need help with this, tell me, i will give you example. this will be all for now. Ciao!

    : I have a tab control in my winform and i have to display a listview with the same set of data loaded in all the tab pages.Do i have to use inheritance or call a procedure?
    :
    :



  • softtips2004softtips2004 Posts: 6Member
    : Actually, there is nothing you should do. if you are using Data Binding to controls, then All the control within that form will be bound altogether. ----- as one pointer change, it is reflected to the other bound controls as well. I don't think there's need for inheritance here. All that is required is, you bind your controls to the same dataset and you're done.
    :
    : And if, you are not working on database, for example you're working on Variables or Constants, a simpler way is put all the Collection in a Module as an array, and if you need to refer to those collection, rather than putting it in all of your controls item collection, create a Sub procedure to load all those data into your Control. If you need help with this, tell me, i will give you example. this will be all for now. Ciao!
    :
    : : I have a tab control in my winform and i have to display a listview with the same set of data loaded in all the tab pages.Do i have to use inheritance or call a procedure?
    : :
    : :
    Dear VCG,Can You Kindly give the code for creating a Sub procedure to load all those data into your Control.

  • VCGVCG Posts: 51Member
    sample code using array:
    1. Draw a TABCONTROL on your form
    2. create at least 2 TAB items on it.
    3. on the first TAB, draw a listbox, named listbox1
    4. on the second TAB, draw a textbox, named textbox1
    5. still on the second tab, draw another combobox, named combobox1

    ' THIS DEFINE AN ARRAY VARIABLE a AND LOAD IT WITH VALUES
    [code]

    public Sub Button1_Click Blah blah blah.......
    'THIS LOADS THE ENTIRE CONTENT OF a TO THE ITEM COLLECTION OF YOUR LISTBOX
    Dim a As String = {"One", "Two", "Three", "Four", "Five"}
    Listbox1.Items.Addrange(a) 'in older vb.net, the syntax is Listbox1.items.all(a)
    Dim i as short
    For i = 0 to listbox1.items.count -1
    combobox1.items.add(listbox1.items(i))
    Next


    End sub
    'on the code view, select class LISTBOX1, and method CLICK and enter the following code

    textbox1.text = listbox1.selecteditem
    [/code]

    As you can see, there is nothing special about using TABCONTROL. You can treat every control that you use as if you are only working on a single form, because you are. As you run the program, any item that you click on the listbox1 in the first TAB, will be the text in textbox1 in the second TAB.

    As you noticed, i could have just use the command combobox1.items.addrange(a) instead of getting the list values from the listbox. i did this to show you how it is done, because at some point in your program (during run time), you may give the user the option to delete an Item in a listbox, this gives you an idea (for...next) on how to update/reflect the new data on the other controls as well in your form so they have synchronized data.

    If you are using controls to a database, the easiest way to do this is to Bind the listbox to a dataset, bind your textbox to the same dataset, and also bind the combobox to the same dataset. provided that you have a connection to database, an adapter, and a dataset, then they will work in harmony. just pay close attention to the Display Member property. if you use that property right, then you will have no problem.however, since it shows you a little confusing list of same datatables, you will need to select the one where you have set restrictions/relations/constraints, and your bounded controls will work fine.


    : : Actually, there is nothing you should do. if you are using Data Binding to controls, then All the control within that form will be bound altogether. ----- as one pointer change, it is reflected to the other bound controls as well. I don't think there's need for inheritance here. All that is required is, you bind your controls to the same dataset and you're done.
    : :
    : : And if, you are not working on database, for example you're working on Variables or Constants, a simpler way is put all the Collection in a Module as an array, and if you need to refer to those collection, rather than putting it in all of your controls item collection, create a Sub procedure to load all those data into your Control. If you need help with this, tell me, i will give you example. this will be all for now. Ciao!
    : :
    : : : I have a tab control in my winform and i have to display a listview with the same set of data loaded in all the tab pages.Do i have to use inheritance or call a procedure?
    : : :
    : : :
    : Dear VCG,Can You Kindly give the code for creating a Sub procedure to load all those data into your Control.
    :
    :



Sign In or Register to comment.