473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Filter Data in the DataGrid system in 3 layers

tsanalista
Staff good day.
I have a problem when that will filter the data in my datagrid.
I am using a system with 3 Layers (BLL, DAL, WIN). Whenever I type something in the textbox generates this error message
/ / Error
* Unable to cast object of type 'System.Collections.Generic.List `1 [BLL.BLL.Students.BLLStudents ]' to type 'System.Data.DataView'.


Expand|Select|Wrap|Line Numbers
  1. Imports System
  2. Imports System.Data
  3. Imports System.Text
  4. Imports System.Text.RegularExpressions
  5. Imports BLL.BLL.Course
  6. Imports BLL.BLL.Students
  7.  
  8. Public Class Form1
  9. #Region "Private Varibales"
  10.     Private _criar As Boolean = False
  11.     Private _editar As Boolean = False
  12.     Private _carregar As Boolean = True
  13.     Private _objc As BLLCourse = Nothing
  14.     Private _objs As BLLStudents = Nothing
  15.     Private _dset As DataSet = Nothing
  16.     Private _dlinha As DataRow = Nothing
  17.     Private _retvalor As Boolean = False
  18.     Private _cursoid As Integer = 0
  19.  
  20.  
  21.  
  22. #End Region
  23.  
  24.  
  25.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  26.         Try
  27.             _objs = New BLLStudents()
  28.  
  29.             _objs.AllStudents()
  30.             DataGridView1.DataSource = _objs.ListaEstudantes
  31.  
  32.         Catch ex As Exception
  33.             MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
  34.             Me.Close()
  35.         Finally
  36.             _objs = Nothing
  37.         End Try
  38.  
  39.     End Sub
  40.  
  41.  
  42. //Textbox
  43.  
  44. Private Sub txtsearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearch.TextChanged
  45.  
  46.         Try
  47.  
  48.             Dim txtstring As String = Me.txtsearch.Text
  49.  
  50.             Dim dv As DataView = Me.DataGridView1.DataSource
  51.  
  52.             dv.RowFilter = "StudentsName LIKE '%" + txtstring + "%'"
  53.  
  54.             Me.DataGridView1.DataSource = dv
  55.  
  56.         Catch ex As Exception
  57.             Throw ex
  58.         End Try
  59.  
  60.     End Sub
  61.  
  62.  
  63.  
  64.  
  65.  

Here BLL Students
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  
  4. Imports System
  5. Imports System.Data
  6.  
  7. Imports DAL.DAL.Students
  8.  
  9. Namespace BLL.Students
  10.     Public Class BLLStudents
  11.  
  12.  
  13. #Region "Variables"
  14.  
  15.         Private _obj As DALStudents = Nothing
  16.         Private _retvalor As Boolean = False
  17.         Private _dset As DataSet = Nothing
  18.         Private _dlinha As DataRow = Nothing
  19.         Private _idvalor As Object = Nothing
  20.  
  21.         Private _StudentsID As Integer
  22.         Private _courseid As Integer
  23.         Private _namestudents As String
  24.         Private _addressstudents As String
  25.         Private _phonestudents As String
  26.         Private _agestudents As Integer
  27.         Private _paidstudents As Boolean
  28.         Private _liststudents As List(Of BLLStudents)
  29.  
  30. #End Region
  31.  
  32.  
  33.      Public Sub AllStudents()
  34.  
  35.             _dset = Nothing
  36.             Try
  37.                 _obj = New DALStudents()
  38.                 _dset = _obj.AllStudents()
  39.  
  40.                 Dim objs As BLLStudents = Nothing
  41.                 _liststudents = New List(Of BLLStudents)
  42.  
  43.                 For index As Integer = 0 To _dset.Tables(0).Rows.Count - 1
  44.                     objs = New BLLStudents
  45.                     objs.StudentsID = _dset.Tables(0).Rows(index)(0).ToString()
  46.                     objs.CursoID = _dset.Tables(0).Rows(index)(1).ToString()
  47.                     objs.EstudanteNome = _dset.Tables(0).Rows(index)(2).ToString()
  48.                     objs.EstudanteEndereco = _dset.Tables(0).Rows(index)(3).ToString()
  49.                     objs.Telefone = _dset.Tables(0).Rows(index)(4).ToString()
  50.                     _liststudents.Add(objs)
  51.                     objs = Nothing
  52.                 Next
  53.  
  54.             Catch ex As Exception
  55.                 Throw ex
  56.             Finally
  57.                 _obj = Nothing
  58.             End Try
  59.  
  60.         End Sub
  61.  
  62.  
I'll leave here a sample of Crud if you want to test:

https://skydrive.live.com/redir?resi...JEWCcmZXmKsI50
Nov 20 '12 #1
11 1874
Rabbit
12,516 Expert Mod 8TB
You can't assign a list object to a dataview object.
Nov 20 '12 #2
so in this case how can I do this kind of research in my Datagrid?
Nov 20 '12 #3
Could you explain how to obtain the same result in this example here?

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtsearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearch.TextChanged
  2.  
  3.         Try
  4.  
  5.             Dim txtstring As String = Me.txtsearch.Text
  6.  
  7.             Dim dv As DataView = Me.DataGridView1.DataSource
  8.  
  9.             dv.RowFilter = "StudentsName LIKE '%" + txtstring + "%'"
  10.  
  11.             Me.DataGridView1.DataSource = dv
  12.  
  13.         Catch ex As Exception
  14.             Throw ex
  15.         End Try
  16.  
  17.     End Sub
  18.  
Nov 20 '12 #4
Rabbit
12,516 Expert Mod 8TB
Here's Microsoft's documentation on how to bind a DataView to a DataViewGrid.
http://msdn.microsoft.com/en-us/library/bb669070.aspx
Nov 20 '12 #5
Okay, thank you. But not exactly fills in the DataGrid I want. I want to make queries according what I type in the textbox.
Just like that I'm returning a List Of, I can not do this kind of query.
Nov 20 '12 #6
I want to take this research using BLL I created ... understand?
If I do it this way there is going to work. But would the design pattern that I am organizing.
Nov 20 '12 #7
Rabbit
12,516 Expert Mod 8TB
I have no idea what you said in post #7.

That's just to bind a dataview to the dataviewgrid. You will still need to do your filtering after it.
Nov 20 '12 #8
Sorry, my English is weak, because I'm from Brazil.
About the project, how do I list the data using my BLL class that returns a List of Students?

Using this model below ..

Expand|Select|Wrap|Line Numbers
  1.  Public Sub AllStudents()
  2.  
  3.             _dset = Nothing
  4.             Try
  5.                 _obj = New DALStudents()
  6.                 _dset = _obj.AllStudents()
  7.  
  8.                 Dim objs As BLLStudents = Nothing
  9.                 _liststudents = New List(Of BLLStudents)
  10.  
  11.                 For index As Integer = 0 To _dset.Tables(0).Rows.Count - 1
  12.                     objs = New BLLStudents
  13.                     objs.StudentsID = _dset.Tables(0).Rows(index)(0).ToString()
  14.                     objs.CursoID = _dset.Tables(0).Rows(index)(1).ToString()
  15.                     objs.EstudanteNome = _dset.Tables(0).Rows(index)(2).ToString()
  16.                     objs.EstudanteEndereco = _dset.Tables(0).Rows(index)(3).ToString()
  17.                     objs.Telefone = _dset.Tables(0).Rows(index)(4).ToString()
  18.                     _liststudents.Add(objs)
  19.                     objs = Nothing
  20.                 Next
  21.  
  22.             Catch ex As Exception
  23.                 Throw ex
  24.             Finally
  25.                 _obj = Nothing
  26.             End Try
  27.  
  28.         End Sub
  29.  
Nov 20 '12 #9
Rabbit
12,516 Expert Mod 8TB
Well, from your first post, it sounds like you're already listing the data. And it sounded like you were having problems filtering the data, not listing it. If you're actually having problems listing it, that's a completely different problem.
Nov 20 '12 #10
Exactly, in the first post, I can solve the problem. Now this would filter the data in the DataGrid using this model Crud as quoted above. But always give this error:

* Unable to cast object of type 'System.Collections.Generic.List `1 [BLL.BLL.Students.BLLStudents]' to type 'System.Data.DataView'.
Nov 21 '12 #11
Rabbit
12,516 Expert Mod 8TB
You're confusing me. You just said you were having problems listing the data but now you say you're not having problems listing the data. So now we're back to the problem originally stated in the first post.

And the solution to that is in post #5 in the link to Microsoft's documentation on binding a dataview to a dataviewgrid. You have to correctly assign it before you can filter on it.
Nov 21 '12 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: ruca | last post by:
Hi gurus, How can I filter data in my DataSet and then put the result in a DataGrid? NOTE: I'm reading a txt file into a dataset with 3 columns: Id, Name, Age I have this: ...
1
by: RockNRoll | last post by:
I'm new to ASP.NET and need to filter a datagrid based on a textbox value. I have a working datagrid and would like the WHERE part of my SQL statement to call the value of a textbox and refresh...
3
by: Juanjo | last post by:
I have a datagrid with two temnplate columns. When a row is in edit mode the each template columns show a dropdownlist (its datasource is a dataview). I need to filter data of second dropdownlist...
1
by: sg | last post by:
Hi I'm starting programming in visual studio and c# and i have a problem with filtering datagrid. I build form with datagrid and i see data from database. I find in microsoft web page...
1
by: Richard Fagen | last post by:
Hi, What are the best practices to filter a datagrid based on user input? For example: I want to display a grid with rows of sales information and allowed the users to specify options (ex:...
9
by: thebison | last post by:
Hi all, I hope someone can help with this relatively simple problem. I am building a timesheet application using ASP.NET C# with Visual Studio 2003.As it is only a protoype application, my...
1
by: datttanand | last post by:
how to filter data in dataset? suppose i want filter the data in dataset with perticuler city..
5
by: Mapi | last post by:
I need help. I am new to MS Access and have been assign this project. I want to be able to filter data from a form that will be displayed on a subform. I don't know if this is possible but...
13
by: ahd2008 | last post by:
Hi everyone, I have a form for departments and personnel. There are there fields for the sake of search: DepartmentSearch as combo box Division\UnitSearch as combo box Number as combo box ...
0
by: karan desai | last post by:
I wanted to filter the data, make changes and the save back to the database. The SQL data adapter and SQL dataset are clashing with TableDataAdapter i.e., db1TableAdpater and DatabseDataSet i.e...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.