Listcontrol text alignment.
-
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
-
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
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.
-
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.
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
-
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
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.
-
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.
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
-
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
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.
-
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.
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