Results 1 to 8 of 8

Thread: DatatGridView Advanced Styling

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2013
    Location
    Newcastle, Australia
    Posts
    158

    DatatGridView Advanced Styling

    Hi Need help in styling a DGV that is attached to a Dataset using the database built in to VB,

    1)How do i go about changing the color of each row

    Example :-
    First Row Background Color = #F1F1F1
    Next Row Background Color = #FFFFFF

    Every Row after that is repeated

    2) How do i Go about having No Border for a column But Border For Rows i.e

    Demo Pic also includes the Row color example from question 1

    Name:  Demo1.png
Views: 313
Size:  59.8 KB

    3) How can i have the whole DGV area filled with empty rows when the form loads

    Example :-

    Say the dataset only has 3 rows of data but the DGV area on the form can contain 9
    How can i make the remainding 6 rows show on screen empty.


    Name:  Demo2.png
Views: 307
Size:  57.2 KB



    Sorry if this is all to much but i have honestly been playing in vb around and browsing google for 2 weeks trying to work this out but have had no luck

    Thanks in advanced

  2. #2
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Re: DatatGridView Advanced Styling

    EDIT: dunfiddlin's post below is the right way and much more effective than this


    Here is what I would do for the background color



    vb.net Code:
    1. Dim yourcolour As New Color
    2.                     yourcolour = ColorTranslator.FromHtml("#FFFFD2")
    3.  
    4.                     Dim yourcolour2 As New Color
    5.                     yourcolour2 = ColorTranslator.FromHtml("#FFFFFF")
    6.  
    7.                    
    8.  
    9.                     For cnt = 0 To (DataGridView1.Rows.Count-1) Step 2
    10.  
    11.                         DataGridView1.Rows(cnt).DefaultCellStyle.BackColor = yourcolour
    12.                         DataGridView1.Rows(cnt + 1).DefaultCellStyle.BackColor = yourcolour2
    13.  
    14.  
    15.                    
    16.                     Next

    That will go through your entire datagridview changing the background colors to the ones your specified.
    Last edited by Crzyrio; May 8th, 2013 at 09:08 AM.

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: DatatGridView Advanced Styling

    1 & 2: Edit the default cell style and the alternating row default cell style. You can do that in the designer by selecting the appropriate properties in the properties window and clicking on the ... button. Cellborderstyle and Borderstyle likewise. As with all properties you can also code for changes at runtime though in this case it's a bit tedious with a lot of values to keep track of.

    3. This one's not possible, especially for a databound DGV, without adding empty rows which would seriously throw off employing the data. If you wanted to do it so that the rows were visible but didn't count, as it were, you would need to customise the control itself and, with some experience in doing just that, I'm really not sure it would be possible even then.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: DatatGridView Advanced Styling

    Quote Originally Posted by Crzyrio View Post
    Here is what I would do for the background color



    vb.net Code:
    1. Dim yourcolour As New Color
    2.                     yourcolour = ColorTranslator.FromHtml("#FFFFD2")
    3.  
    4.                     Dim yourcolour2 As New Color
    5.                     yourcolour2 = ColorTranslator.FromHtml("#FFFFFF")
    6.  
    7.                    
    8.  
    9.                     For cnt = 0 To (DataGridView1.Rows.Count-1) Step 2
    10.  
    11.                         DataGridView1.Rows(cnt).DefaultCellStyle.BackColor = yourcolour
    12.                         DataGridView1.Rows(cnt + 1).DefaultCellStyle.BackColor = yourcolour2
    13.  
    14.  
    15.                    
    16.                     Next

    That will go through your entire datagridview changing the background colors to the ones your specified.
    Really not necessary. The DGV is the most customisable of controls with design wizards aplenty. Alternate row management is completely automatic!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Re: DatatGridView Advanced Styling

    Quote Originally Posted by dunfiddlin View Post
    Really not necessary. The DGV is the most customisable of controls with design wizards aplenty. Alternate row management is completely automatic!
    Fair enough, did not know there was this option -- "alternating row default cell style."

    thanks

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Feb 2013
    Location
    Newcastle, Australia
    Posts
    158

    Re: DatatGridView Advanced Styling

    Thanks guys but i still can not find a way to make the column Borders to not exist so i only have row boarders. (ref to demo pic 2)

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2013
    Location
    Newcastle, Australia
    Posts
    158

    Re: DatatGridView Advanced Styling

    Also How do i have the vertical scroll bar showing on screen but disabled before it is needed

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Feb 2013
    Location
    Newcastle, Australia
    Posts
    158

    Re: DatatGridView Advanced Styling

    WOW got it lol, it was right under my eye the whole time lol just had to have a break to find it lmao

    Thanks for all your help guys. Most appreciated


    Just one thing left

    How do i have the vertical scroll bar showing on screen but disabled before it is needed

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