Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8585183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:59:46+00:00 2026-06-11T21:59:46+00:00

This is a VB.NET, Winforms App. I have a datagridview on Form1 that uses

  • 0

This is a VB.NET, Winforms App. I have a datagridview on “Form1” that uses a databinding.datasource which is an Entity Framework table. I fill the datagridview with the below function on Form1:

Sub PM_UnitViewGrid()
    Try

        _form1.UnitsBindingSource.DataSource = db.units.Where(Function(f) f.propertyId = _form1.CurrentPropertyId).OrderBy(Function(F) F.unitNumber)
        _form1.UnitDataGridView.DataSource = _form1.UnitsBindingSource.DataSource
        Dim iCount As Integer = _form1.UnitDataGridView.RowCount
        For x As Integer = 0 To iCount - 1
            If Not IsNothing(_form1.UnitDataGridView.Rows(x).Cells(4).Value) Then
                Dim tid As Integer = _form1.UnitDataGridView.Rows(x).Cells(4).Value
                Dim _ten As tenant = db.tenants.Single(Function(f) f.Occupantid = tid)
                _form1.UnitDataGridView.Rows(x).Cells(1).Value = _ten.first_name + ", " + _ten.last_name
            Else
                Dim btnColumn As DataGridViewButtonCell = CType(_form1.UnitDataGridView.Rows(x).Cells(1), DataGridViewButtonCell)
                btnColumn.Style.BackColor = Color.Green
                _form1.UnitDataGridView.Rows(x).Cells(1).Value = "VACANT"
            End If
        Next

    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

    Return
End Sub

This works great and also assigns the needed values to an unbound column. The problem is that the cells(1) is a button. Which when clicked takes the user to another form as a new dialog window. The function for which is below. However, once the changes are made in that form I need for the datagridview to refresh the data that its using from the database and show the correct data. As it stands right now the values are not updating on the datagridview unless the app is completely exited and restarted. Nothing I have found seems to work and Refresh and Update only redraw the control. I need the underlying datasource to refresh and then the datagridview once the child form is exited.. This has had me stumped for a good 36 hours now and I am lost as to why nothing I am trying is working. ANY and all help would be greatly appreciated.

The sub that loads the child form based on the cells(1) button clicked is as follows:

Private Sub UnitDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles UnitDataGridView.CellContentClick
    UnitDataGridView.CommitEdit(DataGridViewDataErrorContexts.CurrentCellChange)
    Dim y As DataGridViewCellEventArgs = e
    Dim Tid As Integer = Nothing
    If e.ColumnIndex = 1 Then
        If Not e.RowIndex = -1 Then
            If Not IsNothing(UnitDataGridView.Rows(e.RowIndex).Cells(4).Value) Then
                currentTenent = UnitDataGridView.Rows(e.RowIndex).Cells(4).Value
                TenentIdentification = currentTenent
                If Not IsNothing(e) Then
                    If Not IsNothing(UnitDataGridView.Rows(e.RowIndex).Cells(4).Value) Then
                        Tid = UnitDataGridView.Rows(e.RowIndex).Cells(4).Value
                        Dim _ten As tenant = db.tenants.Single(Function(f) f.Occupantid = Tid) 'tenant is a table entity 
                        TenantViewSubs.tenId = _ten.Occupantid
                        Dim t As New TenantView
                        t.tenId = tid
                        t.ShowDialog()
                    End If
                End If

                PropertyManagSubs.PM_UnitViewGrid() 'This is the function that is above that fills the datagridview
            Else
                Dim uTview As New UnassignedTenants
                uTview.selectedProperty = selectedProperty 'selectedProperty is Integer 
                uTview.ShowDialog()

                PropertyManagSubs.PM_UnitViewGrid() 'This is the function that is above that fills the datagridview
            End If
        End If
    End If
End Sub 

I tried each of the following code blocks after the t.ShowDialog() line with no change at all.

UnitDataGridView.Refresh()

.

UnitsBindingSource.Dispose()
UnitsBindingSource.DataSource = db.units.Where(Function(f) f.propertyId = selectedProperty).OrderBy(Function(f) f.unitNumber)
UnitDataGridView.DataSource = UnitsBindingSource.DataSource

.

UnitsBindingSource.DataSource = nothing
unitsBindingSource.DataSource = db.units.Where(Function(f) f.propertyId = selectedProperty).OrderBy(Function(f) f.unitNumber)
UnitDataGridView.DataSource = UnitsBindingSource.DataSource
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:59:47+00:00Added an answer on June 11, 2026 at 9:59 pm

    I finally fixed this on my own.. It was in the way I passed my db context to the databinding..

    I simply wrote the below sub:

    Private Sub UpdateValues()
        Dim context As New storageEntities 'storageEntities is an Entity
        Dim query = context.units.Where(Function(F) F.propertyId = selectedProperty).OrderBy(Function(f) f.unitNumber)
        UnitDataGridView.DataSource = query
    End Sub
    

    Then anytime a child form updated data I simply call

      UpdateValues()
    

    After the dialog box closes.

    This may help someone else with the same problems so that is why I am posting it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .NET 4 WinForms app that uses the ADO.NET Entity Framework. Some
we have a .NET 3.5 WinForms app that uses Linq2Sql to insert records into
Short Version: I have a WinForms app that uses a .NET 4.0 WebBrowser control
I have a WinForms app that uses the Settings feature of .NET 2, but
I have a .NET Winforms app (created in VS2005) that I deploy using ClickOnce.
I have a C# .NET 2.0 WinForms app. My app has a control that
I have a Winforms App (.NET 3.X) That runs a method in a class
Winforms .net 3.5 app. In my app I have a generic class that looks
I have a .NET 3.5 winforms app that calls a method in a VB6
I have a WinForms .NET app that, according to the Vista Task Manager with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.