Results 1 to 8 of 8

Thread: DGV Format

  1. #1

    Thread Starter
    Addicted Member t3cho's Avatar
    Join Date
    Mar 2014
    Posts
    231

    DGV Format

    I have the DGV loaded from my sql table.

    I have values for status:
    Man = Value 1
    Woman = Value 2

    When i load the table to datagridview i want to format it to Man/Woman instead of 1/2.
    Keep in mind in table it has to be 1 or 2 but in datagridview i need to show man/woman.

    Name:  ed734a5693e237c34393b8c1869a381e.jpg
Views: 167
Size:  8.6 KB

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,470

    Re: DGV Format

    Check this out:

    http://www.vbforums.com/showthread.p...iew&highlight=

    You can create the child table or list yourself to display the text backed by the numbers,

  3. #3

    Thread Starter
    Addicted Member t3cho's Avatar
    Join Date
    Mar 2014
    Posts
    231

    Re: DGV Format

    Assuming this is only for display do i really need to go through all of this.

    In datagridview i only display the sql table. There is no need to edit, delete, add through datagridview.

    Is there any way to loop through the column Spol in datagridview and check

    If value=1 then ' set value of that cell =Man
    else
    value ' set value of that cell =Woman

  4. #4
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: DGV Format

    Instead of doing this at run-time in VB create a new list table in your database.
    All it would contain is:

    GenderID as byte | Gender as string
    1 Man
    2 Woman

    Now in your query you select Gender where GenderID = yourTable.GenderID field (Ones and Twos)
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,470

    Re: DGV Format

    Quote Originally Posted by t3cho View Post
    Assuming this is only for display do i really need to go through all of this.

    In datagridview i only display the sql table. There is no need to edit, delete, add through datagridview.

    Is there any way to loop through the column Spol in datagridview and check

    If value=1 then ' set value of that cell =Man
    else
    value ' set value of that cell =Woman
    That would be far more work. You're already doing most of what's in my example. The extra part is very small.

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,470

    Re: DGV Format

    Quote Originally Posted by Gruff View Post
    Instead of doing this at run-time in VB create a new list table in your database.
    All it would contain is:

    GenderID as byte | Gender as string
    1 Man
    2 Woman

    Now in your query you select Gender where GenderID = yourTable.GenderID field (Ones and Twos)
    I would agree that this should be done regardless. Having apparently meaningless numbers in a database is bad practice. Theer should absolutely be a Gender table and then your gender column contains a foreign key to that table. That way, you can know exactly what the data means by looking at the database alone. You can then use that table to populate the drop-down list in the grid too.

  7. #7
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: DGV Format

    Thanks Jim. You explained that much better than I.

    I work with a closed provideX db these days and do not have the liberty of creating tables.
    I've forgotten much of the nomenclature when discussing these things.
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,972

    Re: DGV Format

    We do things like this a bit differently. Since gender isn't going to be used outside of the "Person" table, we have a field "GenderCode" which is 0,1,2 (unknown, male, female) then another field that is a computed field. it looks at the value of gendercode and returns the correct human-friendly value. this was when we select, there's no joins, no tables to maintain, and allows us to easily select either the code or the value, and for filtering using the code is faster than using the string.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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