Solved

How do i refresh a combobox?

Posted on 2004-09-22
9
557 Views
Last Modified: 2013-11-13
Hi,

I have a form with a combobox, two text boxes and Add/Save/Edit and delete buttons.   When I dad a new record to the database I want to refresh the combobox.

Combobox.datasource = DvAccess(Dataview)

How do I refresh the combobox?  Do i need to reload it,  ie requery the database?  or just update the recordset?

lost and confused

thanks
0
Comment
Question by:Nerdy_Girl88
9 Comments
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 12127577
Did you try

combobox.Refresh

???
0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 12127600
Nopes. Wait. Find out the name of the recorset it is bound to and refresh the bound recordset (call requery).

Is it a plain vanilla ComboBox or a Data bound Combo?
0
 

Author Comment

by:Nerdy_Girl88
ID: 12129114
it is a databound combobox,  bound by a dataview from the data tier,  using vb.net
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:Nerdy_Girl88
ID: 12129300
thisfunction will fill the dataset that the dataview is based on.
-------------------------------------------------------
 Public Function getAccessType() As DataView
        'get the dataview of models for the combobox
        DacboAccess.Fill(DscboAccess1)
        Return Me.DvAccess
    End Function
--------------------------------------------------------
this method is called when the form loads, it will call for the dataset to be filled,  which will populate the combobox.  
--------------------------------------------------------
Private Sub LoadCombobox()
        Dim dvAccess As DataView
        Dim dsAccess As DataSet
        'use try catch to help performance
        Try
            'get the data tier and the dataview
            dvAccess = mobjData.getAccessType
            'bind the dataview to the combobox
            If mblnListInitialized = False Then
                With cboAccessSearch
                    .DataSource = dvAccess
                    .DisplayMember = "Access_Type"
                    .ValueMember = "Access_Type"
                    .SelectedIndex = -1
                End With
                mblnListInitialized = True
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
------------------------------------------------------

to refresh the dataset, i have tried to call the fill LoadCombobox() which i thought would fill the dataset again, with the new data added.

but i get this error on this line.
"DacboAccess.Fill(DscboAccess1)"

there is already a open datareader associated with this conectn which must be closed first.

Whats the dataerader. How can i refresh my dataset?



0
 

Author Comment

by:Nerdy_Girl88
ID: 12131593
I have figured out that you can call the fill method many times. It will merge datarows that have the same prmary key and append new datarows to the dataset.  This will work for edit and add buttons, but it will not work for the delete button.  I want the deleted record to dissapear from the combobox.  Im trying to clear the dataset, before calling the dataAdapter fill method.  But i get this error!  

"object reference not set to an instance of an object."
------------------------------------------------------
Private Sub LoadCombobox()
        Dim dvAccess As DataView
        Dim dsAccess As DataSet
        'use try catch to help performance
        Try
            mobjData.DscboAccess1.Clear() //'this only gives the error when i delete, it performs the delete but with the error.
            dvAccess = mobjData.getAccessType
            'bind the dataview to the combobox
            If mblnListInitialized = False Then
                With cboAccessSearch
                    .DataSource = dvAccess
                    .DisplayMember = "Access_Type"
                    .ValueMember = "Access_Type"
                    .SelectedIndex = -1
                End With
                mblnListInitialized = True
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
---------------------------------------------------

thanks,  nearly solved this problem.
0
 
LVL 3

Expert Comment

by:Statick001
ID: 12134459
what i usually do is create a function which fills an arraylist with the relevant data, and binds the arraylist to the combobox. sorry but i dont use VB so i cant give example code, unless you are happy with c++ or c#

by creating the arraylist within the function, keeps it in local scope inside the function
so every time you call the function, its a new arraylist that is created, and so the combobox updates fine

the problem is, that if you try and bind the combobox to a datasource which it has already been bound to, it won't update. by keeping its datasource (in my example, an arraylist) to being something local to the function, it updates every time
0
 
LVL 3

Expert Comment

by:santosh26676
ID: 12140180
Refresh the DataView and then refresh the combobox.
0
 

Author Comment

by:Nerdy_Girl88
ID: 12140925
The dataview's datasource needs to be refreshed.  dataView DataSource is a dataset,  I have figured out that you can call the datasets fill method multiple times and it will up data this way, however it wll only update changes and new records that have been added to the database, it will not delete data that is in the recordset that isn't present in the database, i have tried to clear the dataset, but not luck.  I will try the refresh.




0
 
LVL 7

Accepted Solution

by:
DrewK earned 500 total points
ID: 12146566
you simply need to REPAINT the form:

if your form is named "frmTest", your code would be:

frmTest.Repaint

or if you are calling it from another form, try: Form_frmTest!Repaint
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
eclipse package explorer vs project explorer view 2 179
recursion example 16 141
egit plugin on eclipse 8 82
Advice in Xamarin 21 97
This article will show, step by step, how to integrate R code into a R Sweave document
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question