Results 1 to 4 of 4

Thread: datagridview question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    92

    datagridview question

    Here is my problem. I have a datagridview that display a list of customers (name, address, zip, phone, etc.) using a FillByLastName(@CustomerLastName). When no customer are found it displays an empty datagridview. I can close it but I would rather it not even be displayed if nothing matches. How do I go about doing this?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: datagridview question

    Test the return value of FillByLastName. If it's zero then there are no matches, so you can either not bind the DataTable to the grid, unbind it if its already (DataSource = Nothing) and Clear the Columns of the grid if necessary.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    92

    Re: datagridview question

    i've tested the return value of fillByLastName but my problem is i'm not writing my own data access code. i'm using datasources. is there a way to unbind it if necessary and have it bound otherwise? i hope that makes since.

    another question? i'm rather new to vb programming, etc. do most programmers write their own code when it comes to accessing data or do they use datasources?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: datagridview question

    If you don't necessarily want the DataTable bound then you shouldn't be binding it in the designer. Clear the DataSource property of your DataGridView in the designer so there's no automatic binding. You can then set the DataSource of the grid in code, if and only if there's data to display.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width