Solved

Need help with DataGridView object

Posted on 2007-11-27
6
175 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 250 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 250 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
Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

 
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

Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

634 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