Clearing Data from Datagrid

Posted on 2006-04-21
Last Modified: 2012-05-05
I'm using the standard Windows form menu script. (see below)

When I clear the field and run the form again, the datagrid will not populate - all other fields do.

 Private Sub ClearFields()

        txbAbr_Id.Text = ""
        DgProblems.DataMember = ""
        lblFirstName.Text = ""
        lblLastName.Text = ""
        txtField.Text = ""
        DgFeesOwed.DataMember = ""
        cboApp.Text = ""

    End Sub

Any suggestions?

Thank you.
Question by:TimSweet220
    LVL 5

    Expert Comment

    How are you populating your datagrid?
    LVL 5

    Expert Comment

    You can try:
    DgProblems.datasource = Nothing

    DgFeesOwed.datasource = Nothing
    LVL 6

    Expert Comment


    dont forget to REFRESH the datagrid
    LVL 34

    Accepted Solution

    From the description it looks as though the bindings for all controls are set either at design time or in some run-once code (e.g. in Form Load).  When you then set a label's or textbox's .Text property to "" you are not breaking the binding, so the next record displays OK.  But when you set a datagrid's .DataMember to "" (or its .DataSource to Nothing) you are breaking the binding, so the next record won't display.

    If this diagnosis is right there are (at least) two options.

    One is to re-bind the datagrid/s as the first step when you re-populate the form.

    The second (which I would prefer) is to clear the fields by clearing the datasource rather than by clearing each of the controls.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    737 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

    19 Experts available now in Live!

    Get 1:1 Help Now