Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need help with DataGridView object

Posted on 2007-11-27
6
Medium Priority
?
178 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
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
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

824 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