Datagridview filtering How-to??
Datagridview filtering How-to??
Datagridview filtering How-to??
Datagridview filtering How-to??
Datagridview filtering How-to??
Datagridview filtering How-to?? Datagridview filtering How-to?? Datagridview filtering How-to?? Datagridview filtering How-to?? Datagridview filtering How-to?? Datagridview filtering How-to?? Datagridview filtering How-to?? Datagridview filtering How-to??
Datagridview filtering How-to?? Datagridview filtering How-to??
Datagridview filtering How-to??
Go Back  Xtreme Visual Basic Talk > > > Datagridview filtering How-to??


Reply
 
Thread Tools Display Modes
  #1  
Old 03-27-2007, 06:12 PM
sgm sgm is offline
Junior Contributor
 
Join Date: Aug 2003
Location: AlBayda, Libya
Posts: 305
Default Datagridview filtering How-to??


Hi
I've been trying to filter a table in a dataset and displaying the filtered table in the same datagridview without having to refill the dataset again, that's to say I don't want to reconnect to my database, I want to reduce trips to my data as much as i can how can i do this.
I've tried to filter a datatable using select but the result won't bind to my datagrid view.
the effect that i'm looking for is the same as in VB6.0 using a filter in a recordset and rebind the datagrid with the filtered recordset and return the original view using adFilterNone.

any ideas ??

thanks
Reply With Quote
  #2  
Old 03-27-2007, 07:07 PM
sgm sgm is offline
Junior Contributor
 
Join Date: Aug 2003
Location: AlBayda, Libya
Posts: 305
Red face found a a solution!

Hi
this is embarrassing If i just waited a little bit longer, any way here is the solution I've came up with...

define a public DataView and DataTable, filling the dataset in the load event of the form and populating the DataTable and DataView in that order with the Requested table.

bind the DataGridView to the DataView.
you can choose how to enter the filtering info, in my case clicking a button but you can choose change event for a TextBox.
now whenever you filter the results will be shown in the DataGridView.

when you want to remove your filter just apply the same filter using * so you will view all the results?

for the last part this resembles the adFilterNone in VB6.0, I couldn't find the equivalent for the DataView, if any can find it please post here.

The RowStateFilter has some interesting options, maybe one of them will have the same effect I'll try it and report back if it has what I'm looking for

I hope this will help new comers to VB2005

here is the code
Code:
'in general section Dim EmpView As New DataView Dim EmpTable As New DataTable Private Sub frmEmployees_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Initializing every thing here Dim cmdEmp As New OleDb.OleDbCommand Dim SQL As String SQL = "tblEmployees" With cmdEmp .CommandText = SQL .Connection = Conn .CommandType = CommandType.TableDirect End With Conn.ConnectionString = ConnStr() Conn.Open() DASchool.SelectCommand = (cmdEmp) DASchool.Fill(dsSchool, "tblEmployees") EmpTable = dsSchool.Tables("tblEmployees") EmpView.Table = EmpTable Me.DataGridView1.DataSource = EmpView Me.DataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically Formatgrid() Conn.Close() Me.txtEmpName.Focus() End Sub 'filtering the data Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click Dim Name As String = InputBox("Enter Employee Name", "Finding Employees") EmpView.RowFilter = ("empName like'" & Name & "'") End Sub 'removing filter "needs revision"?! Private Sub DataGridView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick EmpView.RowFilter = "empName like '*'" End Sub

Bye

Last edited by sgm; 03-28-2007 at 09:14 AM. Reason: correcting typos
Reply With Quote
  #3  
Old 03-27-2007, 11:18 PM
Roger_Wgnr's Avatar
Roger_Wgnr Roger_Wgnr is offline
CodeASaurus Hex

Forum Leader
* Expert *
 
Join Date: Jul 2006
Location: San Antonio TX
Posts: 2,427
Default

From what I can find in MSDN it seems that the Rowfilter can be reset to the Default by assinging an empty string or Null Value.
Quote:
Note You can reset the Expression property by assigning it a null value or empty string. If a default value is set on the expression column, all previously filled rows are assigned the default value after the Expression property is reset.
So you should be able to use
Code:
EmpView.RowFilter = "" 'or EmpView.RowFilter = vbNull
__________________
Code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. ~Martin Golding
The user is a peripheral that types when you issue a read request. ~Peter Williams
MSDN Visual Basic .NET General FAQ
Reply With Quote
  #4  
Old 03-28-2007, 07:23 AM
sgm sgm is offline
Junior Contributor
 
Join Date: Aug 2003
Location: AlBayda, Libya
Posts: 305
Thumbs up Thanks

Hi

that did the trick, thanks a bunch

Bye
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Datagridview filtering How-to??
Datagridview filtering How-to??
Datagridview filtering How-to?? Datagridview filtering How-to??
Datagridview filtering How-to??
Datagridview filtering How-to??
Datagridview filtering How-to?? Datagridview filtering How-to?? Datagridview filtering How-to?? Datagridview filtering How-to?? Datagridview filtering How-to?? Datagridview filtering How-to?? Datagridview filtering How-to??
Datagridview filtering How-to??
Datagridview filtering How-to??
 
Datagridview filtering How-to??
Datagridview filtering How-to??
 
-->