Results 1 to 12 of 12

Thread: [RESOLVED] DGV Column header

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    703

    Resolved [RESOLVED] DGV Column header

    I coded the following to have a DGV Column header appear as specified.

    Code:
                .ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                .ColumnHeadersDefaultCellStyle.Font = New Font("Times New Roman", 11, FontStyle.Bold)
                .ColumnHeadersDefaultCellStyle.ForeColor = Color.Red
                .ColumnHeadersDefaultCellStyle.BackColor = Color.LightSteelBlue
    What I got was this:

    Name:  Headers.jpg
Views: 389
Size:  7.7 KB

    So I have apparently done this wrong, but I am at a loss as to why the color and backcolor failed to execute.

  2. #2
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: DGV Column header

    Maybe it knows red on blue is extremely difficult for most people to read, and impossible for several colorblind people?
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  3. #3
    Fanatic Member
    Join Date
    Feb 2013
    Posts
    985

    Re: DGV Column header

    are you changing cell styles anywhere else, there is a large hierarchy involved with DGV cell styling and its possible what you want is being overridden by something elsewhere in the hierarchy.
    Yes!!!
    Working from home is so much better than working in an office...
    Nothing can beat the combined stress of getting your work done on time whilst
    1. one toddler keeps pressing your AVR's power button
    2. one baby keeps crying for milk
    3. one child keeps running in and out of the house screaming and shouting
    4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
    5. working at 1 O'clock in the morning because nobody is awake at that time
    6. being grossly underpaid for all your hard work


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

    Re: DGV Column header

    I just selected the ColumnHeadersDefaultCellStyle property in the Properties window and pressed F1 to open context-sensitive Help. It opened the MSDN documentation to the page for that property and that page contained this:
    If visual styles are enabled and EnableHeadersVisualStyles is set to true, all header cells except the TopLeftHeaderCell are painted using the current theme and the ColumnHeadersDefaultCellStyle values are ignored.
    I went back to the designer and set the EnableHeadersVisualStyles property to False and, sure enough, I saw in my grid exactly what you apparently expect. All up, it took me about two minutes. At the risk of being accused of making snide remarks, this is how easy it can be to solve your own issues if you just use the Help system built into VS. I've been advocating doing so on this site for well over a decade; since back when I was a newbie with VB and was answering questions on topics I had no experience with simply by using the Help menu in VS. Feel free to think I'm an arrogant ass if you want but please do yourself a favour and use the VS Help system first when you need help.

    By the way, I set all those properties in the designer and I'd suggest that you do the same. I tend to recommend setting all properties in the designer that can be and only using code if the values will change after loading or the values won't be known until loading.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    703

    Re: DGV Column header

    Wow. It always turns out that the more I learn the less I know.

    All snide aside, I did indeed peruse the Help system and was unable to find the information that would provide the answer for this issue. Probably due to the fact that I had no prior knowledge of many of the capabilities residing in VB. On the other hand, I have sometimes been able to consult the help and find exactly what I am looking for.

    It is a crap shoot and I am sure that even professionals such as yourself are not always able to find the information that fits the situation you are in. Certainly I did not, this time.

    I do believe you to be an arrogant ass JM, as I have previously stated, but not in this case. I always consult with the Help System prior to asking a question here. Sometimes I am able to find what I am looking for and sometimes I do not.

    You are probably right about setting every property one can in the designer and not stick them in the code unless absolutely required (I think that is what you meant). Another case of being bitten on the ass because I was doing more than I really needed to do and changing things that really did not require changing.

    Thanks

  6. #6
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: [RESOLVED] DGV Column header

    True story: quoting and linking to the documentation is the professional move. Everything else was there to make JMC feel smarter than you.

    DGV is a complex control with literally hundreds of properties. You should take the time to read as many of the documentation pages as you can. It's not everyone's idea of fun. But 90% of what I learned in early VB was literally just reading random MSDN pages and trying the examples. You can't learn what's there if you don't look! The hard part is "Ugh I need to know how a feature works but I'm not sure it exists". The best way to make that easy is to read about as many features as possible, even the ones you don't need right now, so it becomes, "Ugh dang I remember this was a feature but I forget which dang properties it was."

    You really do need to devote the time to it, though. An entire book could be written JUST about this one control, it's huge.
    Last edited by Sitten Spynne; Dec 6th, 2017 at 08:39 PM.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    703

    Re: [RESOLVED] DGV Column header

    I admit that up until recently I did a lot less of that than I do now. The reason is that much of the material is just not comprehensible unless the person reviewing the material has a base of knowledge that enables understanding. Additionally, my own personal knowledge base is such that frequently I was unable to search any of the reference material and return anything that was even remotely related to what I was wanting to know.

    It has only been in the last few months that I can consult much of the knowledge base, etc. information and even come close to knowing what is being discussed and how it might be applied to my own situation. Kind of like, years ago, when I learned calculus and was able to do things with electronics that had previously just been words with no meaning to me. And as I stated before, when one is searching through any kind of reference material, the first requirement is that there be enough base knowledge such that the search parameters will yield information that actually relates to the task at hand.

    I am learning though and am now finding more and more of the answers to my question on my own. I am trying Sitten, but it is a long slow process.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: [RESOLVED] DGV Column header

    Quote Originally Posted by Sitten Spynne View Post
    True story: quoting and linking to the documentation is the professional move. Everything else was there to make JMC feel smarter than you.
    Teach a man to fish... etc. Slap him with the fish you caught while teaching him how to fish and you may not make a friend but it's not a lesson that will soon be forgotten. I'll say again, I find it rather amusing that I'm the one assuming that others are capable of doing as I do and yet I'm supposedly the one who thinks that I'm superior.
    Quote Originally Posted by Sitten Spynne View Post
    The hard part is "Ugh I need to know how a feature works but I'm not sure it exists".
    That can be the case at times but, if you're using a particular type or member in your own code, you know that type or member exists. Reading the documentation for that type or member is a pretty good place to start.
    Quote Originally Posted by gwboolean View Post
    All snide aside, I did indeed peruse the Help system and was unable to find the information that would provide the answer for this issue. Probably due to the fact that I had no prior knowledge of many of the capabilities residing in VB.
    As I said, you were using the ColumnHeadersDefaultCellStyle property in your code so that would have been a likely place to look. Maybe not the first, as you are using other properties too, but certainly A place to look.
    Quote Originally Posted by gwboolean View Post
    It is a crap shoot and I am sure that even professionals such as yourself are not always able to find the information that fits the situation you are in.
    To say that it's a crap shoot - or even a craps shoot - is significantly overstating the case. It obviously depends on what the actual problem is as to whether you can find the solution in the documentation. I certainly don't claim that you will always find what you need or understand everything you find. Clearly though, what you look for is a big factor in how often you will. Hopefully, whatever else is taken from this thread, you will have a better idea of how to use the Help effectively in future. If you've learned something and your already low opinion of me hasn't been tarnished then I call that a win.

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: [RESOLVED] DGV Column header

    Quote Originally Posted by gwboolean View Post
    I admit that up until recently I did a lot less of that than I do now. The reason is that much of the material is just not comprehensible unless the person reviewing the material has a base of knowledge that enables understanding. Additionally, my own personal knowledge base is such that frequently I was unable to search any of the reference material and return anything that was even remotely related to what I was wanting to know.

    It has only been in the last few months that I can consult much of the knowledge base, etc. information and even come close to knowing what is being discussed and how it might be applied to my own situation. Kind of like, years ago, when I learned calculus and was able to do things with electronics that had previously just been words with no meaning to me. And as I stated before, when one is searching through any kind of reference material, the first requirement is that there be enough base knowledge such that the search parameters will yield information that actually relates to the task at hand.

    I am learning though and am now finding more and more of the answers to my question on my own. I am trying Sitten, but it is a long slow process.
    I think that a big problem is that people tend to search for a question or a clause rather than looking for specific pages on specific types or properties. No doubt experience increases the amount of information that is meaningful but, in this case, going directly to the page for a specific property that you were already using mentioned the exact issue. I'm confident that:
    If [...] EnableHeadersVisualStyles is set to true, [...] the ColumnHeadersDefaultCellStyle values are ignored.
    is something that you don't need too much experience to understand. Maybe I'm wrong about that. I don't think so, but who ever does think that they're wrong without it being demonstrated so? Anyway, the point is that being specific is often a very good idea. If you're using a specific type or member then reading the documentation for that type or member is never a bad idea.

  10. #10
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: [RESOLVED] DGV Column header

    Quote Originally Posted by jmcilhinney View Post
    Teach a man to fish... etc. Slap him with the fish you caught while teaching him how to fish and you may not make a friend but it's not a lesson that will soon be forgotten. I'll say again, I find it rather amusing that I'm the one assuming that others are capable of doing as I do and yet I'm supposedly the one who thinks that I'm superior.

    That can be the case at times but, if you're using a particular type or member in your own code, you know that type or member exists. Reading the documentation for that type or member is a pretty good place to start.

    As I said, you were using the ColumnHeadersDefaultCellStyle property in your code so that would have been a likely place to look. Maybe not the first, as you are using other properties too, but certainly A place to look.

    To say that it's a crap shoot - or even a craps shoot - is significantly overstating the case. It obviously depends on what the actual problem is as to whether you can find the solution in the documentation. I certainly don't claim that you will always find what you need or understand everything you find. Clearly though, what you look for is a big factor in how often you will. Hopefully, whatever else is taken from this thread, you will have a better idea of how to use the Help effectively in future. If you've learned something and your already low opinion of me hasn't been tarnished then I call that a win.
    "Teaching a man to fish", in my book, involves some education about lures, fish behavior, and ultimately providing practical lessons about how to hold the rod, casting, reeling in, etc. I like my student/teacher relationship to be something friendly and rewarding.

    As constructively as I can put it, your style of teaching is, "Here's the book. I'm going to read it to you because clearly you're too lazy." Sometimes you provide the practical lessons. Other times you seem to leave it at "the book has illustrations and I showed it to you, jeez do something on your own for once." This is a "tough love" approach. In literature this usually ends with the student becoming the master via a fight to the death. Very rarely are the people who practice it portrayed as admirable.

    The best parts of your post are where, instead of reading the book to the student, you teach practical lessons. Shoot for this:
    You can read about this feature at [ <list of MSDN links> ], but here's the short version:

    If property A is set, it means property B won't be set. (See <source>.) So if you really need to use property B, you shouldn't set property A. There are many other related properties like that, consider spending an hour or two reading the articles I linked!
    That doesn't come off as patronizing, and still has an awful lot of "read the documentation" in it. You've made quite a few posts like this lately, and when people get upset over them I've been trying to scold them because you've got a volume of knowledge on TableAdapters and DataGridView that'd take me too long to acquire myself and I usually learn something from those answers.

    But when I have to wade through you writing a whole paragraph to say "I think you were too lazy to read the docs" I tend to skip it. It doesn't feel like there'll be anything useful in those posts. You're burying your best content underneath bile and trash.

    Be Mr. Miyagi. Not Ra's al Ghul. They were both teachers who produced excellent students. Only one of them was a respectable man.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  11. #11
    Fanatic Member
    Join Date
    Feb 2013
    Posts
    985

    Re: [RESOLVED] DGV Column header

    i need to butt in here again since i recently quiet often felt the wrath of jmcilhinney ....

    I personally totally agree with your methods to an extent too, if you look at alot of my posts i don't do much coding in replies but i always give some sort of direction and advice at how exactly i might approach something.... (in fact just like you do Jm, but without the snarls behind it <3 as Sitten seemed to point out too and the OP).

    But i take my hat off to you and everyone here for many years you all have helped me tremendously and your skills are very clear.....so dont stop helping me .....

    As for the OP, did you manage to find out what your problem was? i dont seem to see if you got it or how you got it fixed.
    Yes!!!
    Working from home is so much better than working in an office...
    Nothing can beat the combined stress of getting your work done on time whilst
    1. one toddler keeps pressing your AVR's power button
    2. one baby keeps crying for milk
    3. one child keeps running in and out of the house screaming and shouting
    4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
    5. working at 1 O'clock in the morning because nobody is awake at that time
    6. being grossly underpaid for all your hard work


  12. #12
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    Re: [RESOLVED] DGV Column header

    True story: quoting and linking to the documentation is the professional move. Everything else was there to make JMC feel smarter than you.
    You must have forgotten that JMC offers the option of ignoring his posts, thus negating the impending circlejerk

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