[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 146
  • Last Modified:

Clearing Data from Datagrid

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.
0
TimSweet220
Asked:
TimSweet220
  • 2
1 Solution
 
maralansCommented:
How are you populating your datagrid?
0
 
maralansCommented:
You can try:
DgProblems.datasource = Nothing

DgFeesOwed.datasource = Nothing
0
 
hatem72Commented:

dont forget to REFRESH the datagrid
0
 
SanclerCommented:
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.

Roger
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now