473,765 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filter Data in the DataGrid system in 3 layers

tsanalista
11 New Member
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.Collect ions.Generic.Li st `1 [BLL.BLL.Student s.BLLStudents ]' to type 'System.Data.Da taView'.


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 1892
Rabbit
12,516 Recognized Expert Moderator MVP
You can't assign a list object to a dataview object.
Nov 20 '12 #2
tsanalista
11 New Member
so in this case how can I do this kind of research in my Datagrid?
Nov 20 '12 #3
tsanalista
11 New Member
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 Recognized Expert Moderator MVP
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
tsanalista
11 New Member
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
tsanalista
11 New Member
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 Recognized Expert Moderator MVP
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
tsanalista
11 New Member
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 Recognized Expert Moderator MVP
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

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

Similar topics

8
1511
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: code------------------------------------------------------------------------
1
2231
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 the datagrid when a button is clicked. SELECT RateMatrix.Name, RateMatrix., RateMatrix.EC, RateMatrix., RateMatrix. FROM RateMatrix WHERE (. <= TEXTBOX_VALUE_GOES_HERE)
3
1962
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 when the user select an item of first dropdownlist. I have the event OnSelectedIndexChanged of first dropdownlist. I try to use de rowfilter property of dataview with no exit. Is posible to do this? How?
1
8289
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 information how to create filtering data grid but this doesn't work. What I must change? My form code: using System; using System.Collections.Generic; using System.ComponentModel;
1
1381
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: customer and date ranges), then when they click the 'apply filter' button, I want the rows filtered. I've read about methods using a dataview with the rowfilter and sort
9
2748
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 database has been made in MSDE. I have a 'View Resources' page, the purpose of which is to show all employees, taken from that table in the database. This works fine, up to a point. I have a DataGrid, which is done with a DataSet and a
1
1636
by: datttanand | last post by:
how to filter data in dataset? suppose i want filter the data in dataset with perticuler city..
5
2752
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 ideally i would like to double click on a field from Form A which will open a subform and display filtered data based on the data's site code that was double clicked. My database is for a budget tracker
13
3486
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 the user should selcet values form those and press the button( I 'm usnig Macro) to filter data. So far, everything works fine but when re-select other values to look for other data it doesnt work!! it keeps giving me the same result
0
1062
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 GreetingDataset. I wanted to make them working for the above purpose. I am also open for other methods of executing the code. Please help! Here's the code.
0
10164
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8833
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5277
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.