Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Listcontrol text alignment.

Listcontrol text alignment.

Scheduled Pinned Locked Moved C#
question
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #1

    I have a listcontrol in report mode, and I want the text in a particular column to be right aligned. That is, I want to see the end all the time. I cannot find a way to do this, I thought I had, but all I am aligning is the header. Is there a way to align the contents of the column, or do I need to draw the column myself ? Can I draw just one column ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

    U 1 Reply Last reply
    0
    • C Christian Graus

      I have a listcontrol in report mode, and I want the text in a particular column to be right aligned. That is, I want to see the end all the time. I cannot find a way to do this, I thought I had, but all I am aligning is the header. Is there a way to align the contents of the column, or do I need to draw the column myself ? Can I draw just one column ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

      U Offline
      U Offline
      User 1172745
      wrote on last edited by
      #2

      I usually just use the designer to set up my list controls and setup column/header properties (title, alignment, and size) at that time. I've never yet had an instance in the programs I've developed where I didn't know how I wanted data aligned/formatted at design time. Now, one thing I've noticed in general about list controls is that it doesn't seem you can right-align the FIRST column in a list control, but I believe that's a global truth about list controls, and not something specific to WinForms. If at all possible, I would really recommend doing it through the designer. If it's not possible, I'd still recommend doing one through the designer and then look at the code that is generated and compare it with what you're doing. If you can't figure it out still, post some code that can be commented upon.

      C 1 Reply Last reply
      0
      • U User 1172745

        I usually just use the designer to set up my list controls and setup column/header properties (title, alignment, and size) at that time. I've never yet had an instance in the programs I've developed where I didn't know how I wanted data aligned/formatted at design time. Now, one thing I've noticed in general about list controls is that it doesn't seem you can right-align the FIRST column in a list control, but I believe that's a global truth about list controls, and not something specific to WinForms. If at all possible, I would really recommend doing it through the designer. If it's not possible, I'd still recommend doing one through the designer and then look at the code that is generated and compare it with what you're doing. If you can't figure it out still, post some code that can be commented upon.

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        Thanks for your advise. I've moved the column along from the first position, and set it up in the designer to be right aligned, all this does is right align the header ( which didn't happen even when I started ). I'm adding the columns in the designer, and there's a drop down list for text alignment, which I set to 'Right'. This generates the same code I tried to add, something like thelist.Columns.TextAlignment = HorizontalTextAlignment.Right. Thanks for your help. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

        U 1 Reply Last reply
        0
        • C Christian Graus

          Thanks for your advise. I've moved the column along from the first position, and set it up in the designer to be right aligned, all this does is right align the header ( which didn't happen even when I started ). I'm adding the columns in the designer, and there's a drop down list for text alignment, which I set to 'Right'. This generates the same code I tried to add, something like thelist.Columns.TextAlignment = HorizontalTextAlignment.Right. Thanks for your help. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

          U Offline
          U Offline
          User 1172745
          wrote on last edited by
          #4

          If you add Items at design-time (for testing purposes only) through the "Items" collection (you'll have to add SubItems of the first item, just the way list controls work), do these show up right aligned? They do for me when I setup a sample list control through the designer, add columns, and add items. If they show up left aligned, even for fields that you know are right aligned, you've got bigger problems and someone else will have to pipe in with some thoughts (possibly bad COMCTL32???)... If, then, you run your program, only to see everything left aligned, it's pretty obvious that something else is either resetting or recreating the properties on your control. Expand out all the regions of your code and just search for anything related to your list control, paying special heed to anything that may be happening more than once. If you can't isolate it, in the worst case scenario, you can always delete the object off your form/control, and keep re-compiling/fixing errors until you're sure all the code related to the control is gone, then re-add it. I'm sure someone else has other ideas but these are just the ones I can think of.

          C 1 Reply Last reply
          0
          • U User 1172745

            If you add Items at design-time (for testing purposes only) through the "Items" collection (you'll have to add SubItems of the first item, just the way list controls work), do these show up right aligned? They do for me when I setup a sample list control through the designer, add columns, and add items. If they show up left aligned, even for fields that you know are right aligned, you've got bigger problems and someone else will have to pipe in with some thoughts (possibly bad COMCTL32???)... If, then, you run your program, only to see everything left aligned, it's pretty obvious that something else is either resetting or recreating the properties on your control. Expand out all the regions of your code and just search for anything related to your list control, paying special heed to anything that may be happening more than once. If you can't isolate it, in the worst case scenario, you can always delete the object off your form/control, and keep re-compiling/fixing errors until you're sure all the code related to the control is gone, then re-add it. I'm sure someone else has other ideas but these are just the ones I can think of.

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            Thanks - I did all that, and I get a list where the header text is right aligned, but the text in the actual column is not. I am using XP Pro, FWIW. It looks exactly the same as if I play with the code. I added an item, and added subitems until I got to the right column, made that one really long, and I can read the left portion of it, instead of the right. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

            U 1 Reply Last reply
            0
            • C Christian Graus

              Thanks - I did all that, and I get a list where the header text is right aligned, but the text in the actual column is not. I am using XP Pro, FWIW. It looks exactly the same as if I play with the code. I added an item, and added subitems until I got to the right column, made that one really long, and I can read the left portion of it, instead of the right. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

              U Offline
              U Offline
              User 1172745
              wrote on last edited by
              #6

              Ooops, I misunderstood the original post, when I add really long lines, I experience the same behavior you do. I think what you're looking for is definitely possible, but this functionality isn't even available in the Win32 list control (to my knowledge). About the closest thing you could do with the standard control is to add tooltips. Other than that, I think your only choice is making your own custom list control.

              C 1 Reply Last reply
              0
              • U User 1172745

                Ooops, I misunderstood the original post, when I add really long lines, I experience the same behavior you do. I think what you're looking for is definitely possible, but this functionality isn't even available in the Win32 list control (to my knowledge). About the closest thing you could do with the standard control is to add tooltips. Other than that, I think your only choice is making your own custom list control.

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                Yeah, that's what I figured. Thanks for helping me to clarify the point. I guess I'll write such a control towards the end of the project if I find the time. It's my idea, not a specced requirement :-) Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups