Results 1 to 7 of 7

Thread: DataGridView Cell Formatting Issue

  1. #1

    Thread Starter
    Lively Member VisualBrian's Avatar
    Join Date
    Nov 2019
    Location
    North America
    Posts
    72

    Question DataGridView Cell Formatting Issue

    I'm using the following code to number the DGV rows in the Row HeaderCell...
    Code:
        Private Sub DataGridViewTable_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles DataGridViewTable.CellFormatting
            DataGridViewTable.Rows(e.RowIndex).HeaderCell.Value = CStr(e.RowIndex + 1)
        End Sub
    and it works, but the row header blinks like it's constantly cycling through the numbers and the app is sluggish.

    What am I doing wrong?

    EDIT...

    Changed up the code a bit, removed it from CellFormatting and call it whenever the rowcount changes. All is well.
    Code:
    For rowNum As Integer = 0 To .Rows.Count - 1
        DataGridViewTable.Rows(rowNum).HeaderCell.Value = (rowNum + 1).ToString
    Next
    Still not sure why so if anyone knows please enlighten me.
    Last edited by VisualBrian; Jan 28th, 2022 at 08:14 PM. Reason: Solution found
    I may not know anything, but I know it well!

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

    Re: DataGridView Cell Formatting Issue

    Why would you be changing the Value of a cell on an event that exists for formatting? That's what you're doing wrong.
    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 VisualBrian's Avatar
    Join Date
    Nov 2019
    Location
    North America
    Posts
    72

    Re: DataGridView Cell Formatting Issue

    Why would you be changing the Value of a cell on an event that exists for formatting? That's what you're doing wrong.
    You have a very annoying habit of answering a question with a question. Thanks for pointing out my error but explaining why it's wrong would have been much more helpful. To me, anyway. As your response was (and almost always is) for your own benefit, I'm happy to make you feel superior once again. You're welcome.

    Anyway, I thought I asked you to stop responding to my questions.
    I may not know anything, but I know it well!

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

    Re: DataGridView Cell Formatting Issue

    Quote Originally Posted by VisualBrian View Post
    You have a very annoying habit of answering a question with a question.
    That's because I want to prompt people to think for themselves as much as possible. The questions I ask are the sorts of question you should be asking yourself.
    Quote Originally Posted by VisualBrian View Post
    I thought I asked you to stop responding to my questions.
    I'll respond to questions as and when I see fit. You're completely within your rights to ignore any responses you don't like, given that protecting your ego seems more important than learning.
    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

  5. #5

    Thread Starter
    Lively Member VisualBrian's Avatar
    Join Date
    Nov 2019
    Location
    North America
    Posts
    72

    Re: DataGridView Cell Formatting Issue

    You are not my teacher or my daddy. I am not a child or a student. This is not my profession. I am not here for help with my homework. I am a retired Army Veteran and Air Traffic Controller who now stays home and codes for fun. I come here to get help when I get stuck.

    If someone came to me with a question about Air Traffic Control procedures, I would be happy to teach them whatever they wanted to know. I would not call them lazy, or tell them to go look it up, or try to make them feel small. I treat people with respect and expect the same in return.

    In reading many of the posts in which you have responded, I was hard pressed to find one where you actually helped someone. If I must come here again, I hope you'll try to not post to me unless you actually want to help. I think that's a reasonable request, but as you said, you can do whatever you like.
    I may not know anything, but I know it well!

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

    Re: DataGridView Cell Formatting Issue

    Quote Originally Posted by VisualBrian View Post
    In reading many of the posts in which you have responded, I was hard pressed to find one where you actually helped someone.
    You're obviously right. In 17 years and over 100,000 posts, I've never helped anyone. I have to confess, I hacked the system and added over 11,000 reputation points myself. I knew someone would find me out eventually. Good job.
    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

  7. #7
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,129

    Re: DataGridView Cell Formatting Issue

    Quote Originally Posted by jmcilhinney View Post
    You're obviously right. In 17 years and over 100,000 posts, I've never helped anyone. I have to confess, I hacked the system and added over 11,000 reputation points myself. I knew someone would find me out eventually. Good job.
    oh you little tasmanian devil https://www.youtube.com/watch?v=tRE52ZUJ0gc
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

Tags for this Thread

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