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 9081913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:25:50+00:00 2026-06-16T20:25:50+00:00

I have a DataGridview that displays the data and a TextBox that allows me

  • 0

I have a DataGridview that displays the data and a TextBox that allows me to filter the BindingSource with an SQL query to display the data based on the input string. This is all working fine apart from once I have filtered the DataGridView the timer function I have is resetting it back so all the data is being displayed again. The timer is set on a 1000ms basis, so it will show the filtered result for a second, then revert back.

Heres my code:

Imports System.Data.OleDb

Public Class Form1

    Dim duraGadgetDB As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = C:\Users\Dave\Documents\duraGadget.mdb;"
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sql As String = "SELECT * FROM duragadget"
        Dim connection As New OleDbConnection(duraGadgetDB)
        Dim dataadapter As New OleDbDataAdapter(sql, connection)
        Dim ds As New DataSet()
        connection.Open()
        dataadapter.Fill(ds, "dura")
        connection.Close()
        DataGridView1.DataSource = ds
        DataGridView1.DataMember = "dura"
        DataGridView1.Columns(5).Width = 300 
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        insert.Show()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim currentRowID As Integer
        Dim scrollPosition As Integer = DataGridView1.FirstDisplayedScrollingRowIndex
        Try
            If DataGridView1.CurrentRow IsNot Nothing Then

                currentRowID = DataGridView1.CurrentRow.Index

                Dim sql As String = "SELECT * FROM duragadget"
                Dim connection As New OleDbConnection(duraGadgetDB)
                Dim dataadapter As New OleDbDataAdapter(sql, connection)
                Dim ds As New DataSet()
                connection.Open()
                dataadapter.Fill(ds, "dura")
                connection.Close()
                DataGridView1.DataSource = ds
                DataGridView1.DataMember = "dura"
                DataGridView1.CurrentCell = DataGridView1.Item(1, currentRowID)
            End If
        Catch ex As Exception

        End Try
        DataGridView1.FirstDisplayedScrollingRowIndex = scrollPosition
    End Sub

    Private Sub txtSearchOnSku_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearchOnSku.TextChanged
        Dim currentRowID As Integer
        Dim scrollPosition As Integer = DataGridView1.FirstDisplayedScrollingRowIndex
        Try
            If DataGridView1.CurrentRow IsNot Nothing Then
                currentRowID = DataGridView1.CurrentRow.Index
                Dim sql As String = "SELECT * FROM duragadget"
                Dim connection As New OleDbConnection(duraGadgetDB)
                Dim dataadapter As New OleDbDataAdapter(sql, connection)
                Dim ds As New DataSet()
                Dim dsView As New DataView
                Dim bs As New BindingSource()
                connection.Open()
                dataadapter.Fill(ds, "dura")
                connection.Close()
                dsView = ds.Tables(0).DefaultView
                bs.DataSource = dsView
                bs.Filter = "skuNo LIKE'" & txtSearchOnSku.Text & "*'"
                DataGridView1.DataSource = bs
                DataGridView1.CurrentCell = DataGridView1.Item(1, currentRowID)
            End If
        Catch ex As Exception
        End Try
        DataGridView1.FirstDisplayedScrollingRowIndex = scrollPosition
    End Sub
End Class

Can anyone tell me how to stop this happening?

  • 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-16T20:25:56+00:00Added an answer on June 16, 2026 at 8:25 pm

    Assuming you mean that, if you have entered a value in your text box to filter your results, that you then don’t want you timer to fire and unfilter them…

    You can either, check the contents of the TextBox in the Timer1_Tick routine;

    If txtSearchOnSku.Text <> "" Then Exit Sub
    

    Or you can disable your timer in the txtSearchOnSku_TextChanged routine;

    If txtSearchOnSku.Text <> "" Then 
       Timer1.Stop
    Else
       Timer1.Start
    End If
    

    Or, if you want to update your results once a second, based on you search, you can include the Filtering code in your Timer1_Tick routine.

    As a quick point, you have alot of repeated code there. It may be worthwhile refactoring the repeated code out into another sub.

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

Sidebar

Related Questions

I have a DataGridView that displays data from a MS Access database. I'm using
I have a datagridview that displays data from an XML file. The DGV is
I have an application that displays the data of a sql database in a
I want to have a multiline textbox to display data in a DataGridView. I
In my application I have a DataGridView control that displays data for the selected
Ok, I have a DataGridView that I'd like to load with data that I'm
Hey guys, I have an application that I want to display some data from
I have a Gridview that displays some data. What im trying to do is
On my main window I have a DataGridView that I wish to display my
I have a DataGridView that displays a list of MMS Messages. To differentiate between

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.