Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need help with DataGridView object

Posted on 2007-11-27
6
Medium Priority
?
176 Views
Last Modified: 2013-11-26
I need a little assistance with DataGrids. I can bind the grid and have it show data no problem, but the table it is bound to I  don't want to show all the data, just data based on the  current order number (which is a column in the table). Can anyone assist me on this issue?
0
Comment
Question by:rolltide0
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 18

Accepted Solution

by:
vbturbo earned 1000 total points
ID: 20357529
try this

Private myView As DataView

    Private Sub txtsearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearch.TextChanged
                With myView
                    .RowFilter = "Convert("OrderNumberColumn", 'System.String')  Like '%" & txtsearch.Text & "%'"
                    .RowStateFilter = DataViewRowState.CurrentRows
                End With

                dgv.DataSource = myView
end sub

vbturbo
0
 
LVL 9

Expert Comment

by:JonMny
ID: 20357597
    Dim s As New BindingSource()
       s.DataSource = lst
        Me.DataGridView1.DataSource = s
        s.Filter = "Ordernumber = 2"
0
 
LVL 27

Assisted Solution

by:VBRocks
VBRocks earned 1000 total points
ID: 20358612
Hi, I hope you don't mind me chiming in...

This is similar to vbturbo's, however, it does not use the Convert method, or the LIKE operator, which
is an important difference, because this example will only return exact matches, which is what I think
you are looking for:

First of all, when you set the DataSource for your DataGridView, set it to the table's DataView, and
not the actual table itself, for example:

        'Create a table as an example:
        Dim table As New DataTable()
        table.Columns.Add("CurrentOrderNumber")
        table.Columns("CurrentOrderNumber").DataType = GetType(Int32)
        table.Columns.Add("Item")

        For i As Int16 = 1 To 10
            table.Rows.Add(i, "Item " & i)
            table.Rows.Add(i, "Item " & i)
        Next


        'Set the DataSource to the DataView of the table
        Me.DataGridView1.DataSource = table.DefaultView


'Then, when you want to perform filtering based off of a order number, you can do it like this, and it
will only return exact matches.

        'You can set this to whatever number your are looking for
        Dim OrderNumber As Int32 = 5

        Dim view As DataView = Me.DataGridView1.DataSource
        view.RowFilter = "CurrentOrderNumber=" & OrderNumber

        Me.DataGridView1.DataSource = view


One thing to think about:  The DataView will perform far better with fewer records in it, than a lot,
(for example - 5000+).  So filtering the DataView works great with fewer than say, 5000 records.  So
if you are thinking about having lots of records in the DataGridView, and then letting the user filter them,
you may want to think about filtering them in the Database they are coming from (like SQL, or Access,
etc.).  That way, if you have 25,000 orders in your database, don't retrieve all 25,000, and then let
the user filter the ones they want, but rather let the user select the ones they want (enter an order
number), then filter them with SQL when you retrieve them from the database.




0
Amazon Web Services EC2 Cheat Sheet

AWS EC2 is a core part of AWS’s cloud platform, allowing users to spin up virtual machines for a variety of tasks; however, EC2’s offerings can be overwhelming. Learn the basics with our new AWS cheat sheet – this time on EC2!

 
LVL 18

Expert Comment

by:vbturbo
ID: 20360344
VBRocks has provided you with a very good approach when handling a great amount of rows.
i agree with him.

Though you should let the database do what it is best to , handle perfomance heavy jobs.
This is what it is designed for among others.

My point of view is that when having a fair amount of rows and perhaps long order numbers
maybee 5-15 digits or even longer then there is a big advantice in filtering when typing.

so whatever choise you make , i think it comes down to user interaction,taste and performance < 1000 rows.

vbturbo

 
0
 

Author Comment

by:rolltide0
ID: 20443409
All three of you all gave great suggestions. Due to finals I haven't had the opportunity to try any of them. Vbturbo, can you explain your solution with a little more detail? The convert method is something I am not familiar. So if you have time, a line by line explanation would be very helpful.
0
 
LVL 18

Expert Comment

by:vbturbo
ID: 20450672
Hi

When filtering on column data which is (type of) integer then you can only use the "=" equal operator
as suggested by VBRocks.
:Display's only a match in the filter when it exacly match's your filter argument
 

By using the convert tostring method on the column (integer) you can now apply the LIKE operator on the
column filter.
:Display's all records which match each time you type a argument in your txtbox.

Try have a look on table column expressions
http://msdn2.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx

vbturbo

0

Featured Post

Amazon Web Services EC2 Cheat Sheet

AWS EC2 is a core part of AWS’s cloud platform, allowing users to spin up virtual machines for a variety of tasks; however, EC2’s offerings can be overwhelming. Learn the basics with our new AWS cheat sheet – this time on EC2!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question