Solved

How do i refresh a combobox?

Posted on 2004-09-22
9
540 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
 

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VB 6.0 printer how to align 6 49
stringclean challenge 26 56
Path of Workbook 3 45
Non-recursive backtracking, using a stack 1 48
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now