VB .NET DataGrid retaining data from prior use.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RoMo
    New Member
    • Apr 2007
    • 1

    VB .NET DataGrid retaining data from prior use.

    I am using VB .NET (2003) for a project that includes a datagrid on one form that allows the user to switch to details on a second form. The datagrid was built in design mode with all the proper style information.
    The user types in a part of a company name and a database search returns matching data (via ADO) to a dataset. If more than 1 matching company was found, the datagrid is made visible and has its source and member assigned to the table in the dataset. All appears fine. The user clicks on one item in the grid and the program senses the item, locates the company in the database, retrieves detailed data and displays on the secondary form. The user can then return to the first form and select a different item on the grid to follow a path.
    If the user does not want anything in the current grid, they START OVER and enter a new search string. My program retrieves new data into the DataSet however the grid appears to "remember" items that were selected during a prior use. Their retained text values appear in the new grid in place of data in the actual underlying dataset.

    How do I tell the data grid to forget it was ever used before and start fresh with no current cell or remembered selections?
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Reassign the datagrid using the New identifier.


    Originally posted by RoMo
    I am using VB .NET (2003) for a project that includes a datagrid on one form that allows the user to switch to details on a second form. The datagrid was built in design mode with all the proper style information.
    The user types in a part of a company name and a database search returns matching data (via ADO) to a dataset. If more than 1 matching company was found, the datagrid is made visible and has its source and member assigned to the table in the dataset. All appears fine. The user clicks on one item in the grid and the program senses the item, locates the company in the database, retrieves detailed data and displays on the secondary form. The user can then return to the first form and select a different item on the grid to follow a path.
    If the user does not want anything in the current grid, they START OVER and enter a new search string. My program retrieves new data into the DataSet however the grid appears to "remember" items that were selected during a prior use. Their retained text values appear in the new grid in place of data in the actual underlying dataset.

    How do I tell the data grid to forget it was ever used before and start fresh with no current cell or remembered selections?

    Comment

    • svac
      New Member
      • Apr 2007
      • 1

      #3
      clear the dataset every time when a new search is made.
      That is in the click event after your dataset initialization
      put the code
      YourDataSet.Cle ar()

      Comment

      • radcaesar
        Recognized Expert Contributor
        • Sep 2006
        • 759

        #4
        After your first transaction for the click is over, Dispose the Dataset and DataAdapter. Next time create a new one and use that.

        :)

        Comment

        • brunko
          New Member
          • May 2007
          • 1

          #5
          I am disposing the dataset and the dataadapter and the highlighted items still carry over to the new data.

          Comment

          Working...