Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filtering data with Datagrid

Status
Not open for further replies.

Jacksparrow87

Technical User
Jun 29, 2008
93
GB
Hi people I was hoping someone could offer me some help please as Im struggling a bit on some datafiltering (well it does what its suppose to do but not what I want it to)

What I want to do is if I choose lets say record 23 and then enter data in txtsearch I want to filter the data however I don't want to select record 1, currently if I choose record 23 and then enter some data to be filtered it automatically selects record 1 but I still want record 23 to be selected and NOT record 1.

so far I have the following coding

Code:
'Sql statement 
'Select row 
Dim ptr As Integer 
        For ptr = 0 To dt.Rows.Count - 1 
            If dt.Rows(ptr).Item("LogNumber").ToString = lbllog.Text Then 
                'highlight row matching new criteria 
                dglog.Select(ptr) 
                'make sure row is in sight 
                dglog.CurrentRowIndex = ptr 
                'apply changes 
                dglog.Refresh() 
                Exit For 
            End If 
        Next 
'show logno in another label 
        lbltest.Text = lbllog.Text 
'filter data 
       Dim dvfilter As DataView = Nothing 
        If TypeOf dglog.DataSource Is DataView Then 
            dvfilter = CType(dglog.DataSource, DataView) 

        ElseIf TypeOf dglog.DataSource Is DataTable Then 
            dvfilter = CType(dglog.DataSource, DataTable).DefaultView 
        End If 

        If txtsearch.TextLength > 0 Then 
            dvfilter.RowFilter = String.Format("LogNo LIKE '{0}*' ", _ 
      txtsearch.Text) 
        Else 
            dvfilter.RowFilter = "" 
        End If 
        dglog.DataSource = dvfilter 

'select record again 
        Dim ptrt As Integer 
        For ptrt = 0 To dt.Rows.Count - 1 
            If dt.Rows(ptrt).Item("ID").ToString = lbltest.Text Then 
                'highlight row matching new criteria 
                dglog.Select(ptrt) 
                'make sure row is in sight 
                dglog.CurrentRowIndex = ptrt 
                'apply changes 
                dglog.Refresh() 
                Exit For 
            End If 
        Next

However the problem is it does not select the same row, it selects a random row for some reason.

Any help please.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top