XE4 Delphi TCustomListView TViewStyle 'vsSmallIcon' badly arranged Icons
Asked Answered
W

0

28

I'm using TListView in my form (which inherits from TCustomListView) and when I change ListView style to "vsSmallIcon" the icons gets badly arranged. We found this issue ever since we ported our Code from Borland 2006 to XE4. Rest all "ViewStyle"s like vsIcon, vsList & vsReport are working fine. Did anyone faced similar issue with VCL's TlistView component? I have already tried ListView1->Arrange(arDefault) and 'AutoArrange' Icon Options but nothing seems to work for 'vsSmallIcon' TViewStyle.

I'm on Windows 7 and using RAD Studio XE4 with Update1.

Thanks,
Santosh Thankachan
PS: Added an image to show this issue with vsSmallIcon TViewStyle.

TCustomListView TViewStyle vsSmallIcon Badly arranged Icons Borland 2005 TListView 'vsSmallIcon' are neatly arranged

Code is as follows:

//SmallIconIssue.h
#ifndef SmallIconsIssueH
#define SmallIconsIssueH
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ImgList.hpp>
#include <Vcl.ComCtrls.hpp>
class TSmallIconTest : public TForm
{
__published:    // IDE-managed Components
  TImageList *ImageList1;
  TComboBox *ComboBox1;
  TListView *ListView1;
  TLabel *Label1;
  void __fastcall FormCreate(TObject *Sender);
  void __fastcall ComboBox1Click(TObject *Sender);
private:    // User declarations
public:     // User declarations
  __fastcall TSmallIconTest(TComponent* Owner);
};
extern PACKAGE TSmallIconTest *SmallIconTest;
#endif

//SmallIconIssue.cpp
#pragma package(smart_init)
#pragma resource "*.dfm"
TSmallIconTest *SmallIconTest;
__fastcall TSmallIconTest::TSmallIconTest(TComponent* Owner) : TForm(Owner) {}

void __fastcall TSmallIconTest::FormCreate(TObject *Sender) {
  const char Names[42][2][10] =
   {{"Rubble","Barny"},
    {"Michael", "Johnson"},
    {"Bunny", "Bugs"},
    {"Silver", "HiHo"},
    {"Silver1", "HiHo1"},
    {"Silver2", "HiHo2"},
    {"Silver3", "HiHo3"},
    {"Silver4", "HiHo4"},
    {"Silver5", "HiHo5"},
    {"Silver6", "HiHo6"},
    {"Silver7", "HiHo7"},
    {"Silver8", "HiHo8"},
    {"Silver9", "HiHo9"},
    {"Silver11", "HiHo11"},
    {"Silver22", "HiHo22"},
    {"Silver33", "HiHo33"},
    {"Silver44", "HiHo44"},
    {"Silver55", "HiHo55"},
    {"Silver66", "HiHo66"},
    {"Silver77", "HiHo77"},
    {"Simpson1", "Bart1"},
    {"Simpson2", "Bart2"},
    {"Simpson3", "Bart3"},
    {"Simpson4", "Bart4"},
    {"Simpson5", "Bart5"},
    {"Simpson6", "Bart6"},
    {"Simpson7", "Bart7"},
    {"Simpson8", "Bart8"},
    {"Simpson9", "Bart9"},
    {"Simpson11", "Bart11"},
    {"Simpson22", "Bart22"},
    {"Simpson33", "Bart33"},
    {"Simpson44", "Bart44"},
    {"Simpson55", "Bart55"},
    {"Simpson66", "Bart66"},
    {"Simpson77", "Bart77"},
    {"Simpson88", "Bart88"},
    {"Simpson99", "Bart99"},
    {"Simpson00", "Bart00"},
    {"Simpson12", "Bart12"},
    {"Simpson13", "Bart13"},
    {"Squirrel", "Rocky"}};

  TListItem *Item;
  TListColumn *Column;
  const char imagenames[30][30] = {
    "Borland2 Image akjlhfkja",
    "Borland3 Imagewerq r",
    "Borland4 Rest qew reqwr",
    "Borland5 Imagedf fa",
    "Borland6 Free df ",
    "Borland7 Image af ",
    "Borland8 Clear ad3e",
    "Borland9 Image123 ",
    "Borland11 df d",
    "Borland22 Imagea fa f",
    "Borland33 hmmm f sdf f",
    "C++ Image",
    "Borland1 Test",
    "Borland44 Imageq3r r",
    "Borland55 abcdefg rest",
    "Borland66 Imageq tr trt",
    "Borland77 no rest atall dg",
    "Borland88 Imageqtree",
    "Borland99 Free VCL tree",
    "Borland12 Imagedf fa",
    "Borland23 Blurr df d",
    "Borland34 r",
    "Borland45 Rest qew reqwr",
    "Borland56 Free df ",
    "Borland67 Image123 ",
    "Borland78 Imagea fa f",
    "Borland89 Being",
    "Borland90 AdFree",
    "Borland13 Image akjlhfkja",
    "Delphi23 Image color"
  };
  const char Col2Array[30][60] =
  {
    "Documentation for the C++ icon.",
    "Borland1 icon test.",
    "Borland2 icon. Rest sar",
    "Borland3 icon Free .",
    "Borland4 icon Tree. af",
    "Borland6 icon Kree kjadsf k.",
    "Borland7 icon lest hghghg.",
    "Borland8 icon mnmnm.",
    "Borland9 icon jiop werq .",
    "Borland0 icon terere df af .",
    "Borland5 icon nmijh fdferfr .",
    "Borland11 icon Clear vc.",
    "Borland22 icon Image sdgfsdg.",
    "Borland33 icon Picture t4.",
    "Borland44 iconv Congress25245.",
    "Borland55 icon Labor 25v545.",
    "Borland66 icon tony b3764656.",
    "Borland77 icon 5 Abott reg354.",
    "Borland88 icon. Rest sar",
    "Borland99 icon Kevin 342455vreg354.",
    "Borland00 icon test.",
    "Borland12 icon Free .",
    "Borland23 icon Kree kjadsf k.",
    "Borland34 con Tree. af",
    "Borland56 icon nmijh fdferfr .",
    "Borland45 icon mnmnm.",
    "Borland56 icon jiop werq .",
    "Borland78 icon terere df af .",
    "Borland89 icon lest hghghg.",
    "Delphi90 icon Rudd 45c rewffretew."
  };

  ListView1->SmallImages = ImageList1;
  ListView1->LargeImages = ImageList1;

  for (int i = 0; i < ImageList1->Count; i++)
  {
    Item = ListView1->Items->Add();
    Item->Caption = imagenames[i];
    Item->ImageIndex = i;
    Item->SubItems->Add(Col2Array[i]);
  }
  // Create two columns to show during viewing as vsReport
  Column = ListView1->Columns->Add();
  Column->Caption = "Image Name";
  Column->Width = 200;
  Column = ListView1->Columns->Add();
  Column->Caption = "Image Description";
  Column->Width = 200;

  // Add View styles and constants to the Combo Box
  ComboBox1->Items->AddObject("vsIcon", reinterpret_cast<TObject *>(vsIcon));
  ComboBox1->Items->AddObject("vsList", reinterpret_cast<TObject *>(vsList));
  ComboBox1->Items->AddObject("vsReport", reinterpret_cast<TObject *>(vsReport));
  ComboBox1->Items->AddObject("vsSmallIcon", reinterpret_cast<TObject *>(vsSmallIcon));

  // Display First item in the Combo Box and arrange ListView accordingly...
  ComboBox1->ItemIndex = 0;
  ListView1->ViewStyle = (TViewStyle) ComboBox1->Items->Objects[ComboBox1->ItemIndex];
  ListView1->Arrange(arDefault);
}

void __fastcall TSmallIconTest::ComboBox1Click(TObject *Sender)
{
  ListView1->ViewStyle = (TViewStyle) ComboBox1->Items->Objects[ComboBox1->ItemIndex];
  ListView1->Arrange(arDefault);
}
Wordless answered 16/9, 2013 at 2:0 Comment(22)
Try calling ListView.Arrange(arDefault); in f.i. OnCreate of your form, also be sure to have IconOptions.AutoArrange 'true' for when you're deleting an item etc.. Does it help?Sluff
I tried both already but nothing works, it seems that its some kind of inherent issue with TCustomListview component.Wordless
Well, then that's a different issue than I have faced (not with XE4, i don't have it). (here you go with your 10 pt.s)Sluff
I still do not have enough reputation points to post an image :(. Strange limitation from StackOverflow...Wordless
Post a link to an image-hosting site (eg imgur) and someone else can edit your question to add the image for you.Admonish
Thanks David M for his comment, it just increased my reputation enough to add an Image :)Wordless
Playing with the IconOptions I'd deem this behavior as designed. (Same on D 2010)Minorca
I don't think its As-Designed as in Borland 2005 Small Icons were neatly arranged (Check the Other snapshot I attached). It looks like this is Broken in XE4.Wordless
Wait, and as an answer you expect to say yes or no depending on if the answerer experienced the problem you have ? With a component descendant we've never seen and don't know its code ? Another nice question where I'm wondering how could it ever get so many upvotes. Nice, SO users! [not voting down, just to close though]Labellum
Can we have an SSCCE?Reclusion
Hi David, I just customized a sample VCL code from following link docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/… Hope this will suffice? Thanks, SantoshWordless
Nope. That's not an SCCEE. You are asking us to make the SSCCE. I've personally got other things to do.Reclusion
It's unclear to me which picture illustrates the preferred icon layout. Both have their merits. In the first, it's clear that there's a fixed column width of x, yet most icon labels require a width of 2 x. For those that don't, the next item is placed only x pixels away. In the second image, the column width is calculated dynamically according to the widest item in the list. Instead of showing pictures of two different programs, maybe you could show images of the same program compiled with different Delphi versions.Weiner
This doesn't have anything to do with Delphi XE4, or Delphi 2006 for that matter. What you see is a different implementation of the listview control in version 6 of comctl32 vs. version 5 of comctl32. IOW you'll get the old look if you don't use v6 comctl32, you can arrange that in 'project options', 'application' - select 'none' as runtime themes.Sluff
Presumably you should be able to send a CCM_SETVERSION to the control to same effect (saving the application), but I'm yet to encounter any success of sending CCM_SETVERSION.Sluff
@DavidHeffernan, I have tried to add the code for the same, I could have attached the whole project in Zip format but don't know how to attach the same in the Report. RobKennedy, I have Updated the same Code build with different versions of Delphi now. Hope this helps a bit. SertacAkyuz, Your theory makes sense and I have already selected Run-time Themes as 'None'. Can you please give some more inputs on how we can force a particular piece of Code to use older comctl32?Wordless
@Santosh - Well, I already said what I know. There's CCM_SETVERSION which's supposed to provide the behavior of a particular version, but apparently either this is no such behavior or it doesn't work. But if you've selected runtime themes as none, you don't need any other thing.Sluff
Wait, is this a Delphi question or a C++ question?Jocko
@CraigYoung This is an issue I found with our C++ code when we moved to XE4 Update 1 (from Borland 2005). I just wanted to be sure if anyone else faced similar issue and if there exists some kind of Solution to fix this. If others agree that its some kind of issue with TCustomListView in XE4 then I may try to log the same in Embarcadero itself.Wordless
@Santosh - I don't know others, but my opinion is that Emb would dismiss it as '3rd party'. I'd be very curious of a result of a test that you could perform. In the Delphi2005 test program, at least double your imagenames[10], this one "Borland33 hmmm f sdf f". Make it anything at least twice the length, and run the test program. Do not change the width of the ListView in this test. I'd be surprised if you will not see the very same defect with your XE4 test.Sluff
@SertacAkyuz, shouldn't that be the answer?Location
@Location - Probably so. But the OP didn't bother to make that test, or to disclose the result. So I don't know for sure.Sluff

© 2022 - 2024 — McMap. All rights reserved.