1

I'm trying to edit ShellCtrls.pas, but I don't have any idea where the part of component is located to create the ListView column.

I need only 1 column to show the name of the file/folder in the ListView without other columns for size, detail, etc.

For now, I just edit the part from TCustomSystmListView.EnumColumns(), adding this code in the end finally section:

    if Columns.Count > 4 then begin
      Column[4].Destroy;
      Column[3].Destroy;
      Column[2].Destroy;
      Column[1].Destroy;
    end else
    if Columns.Count > 3 then begin
      Column[3].Destroy;
      Column[2].Destroy;
      Column[1].Destroy;
    end else 
    if Columns.Count > 2 then begin
      Column[2].Destroy;
      Column[1].Destroy;
    end else if Columns.Count > 1 then begin
      Column[1].Destroy;
    end;

It works well for now, but I know that it is not the correct way to do that. I hope someone can tell me how to make this component create only 1 column in the correct way?

PS: any example from Delphi 10.4 or Delphi 7 is okay. I have that component in both versions. I see the code is not far different.

I want the component to only create 1 column by default.

image

From this screenshot, I just need the column in the green box and don't want the column in the red box.

How to do this from editing code in ShellCtrls.pas?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
NettixCode
  • 25
  • 1
  • 4
  • Your `if then ... else if then ...` can be greatly simplified into a simple `for` loop, eg: `for i := Columns.Count-1 downto 1 do Column[i].Destroy;` But this is assuming the `Name` column is always at index 0, but I don't see anything in the ShellCtrls code that enforces that (except when the `RootFolder` does not support `IShellFolder2` or `IShellDetails`, and its `Properties` has `fpFileSystem` enabled), so you may have to instead iterate the whole `Columns` list destroying any columns whose `Name` property is not `'Name'` (which I imagine can be localized). – Remy Lebeau May 12 '23 at 16:06
  • Otherwise, in `TCustomShellListView.EnumColumns()`, it seems that it might be possible to just edit `AddDefaultColumns()` to ignore any value of `ColCount` that is `> 1`, and edit the `GetDetailsOf()` loops to ignore any `Col` value that is `> 0`. But again, that is assuming `Name` is always the 1st column. – Remy Lebeau May 12 '23 at 16:09
  • That being said, given what you want to achieve, it seems that a better solution would be to simply iterate the folder yourself and populate your own ListView however you want instead of butchering `TCustomShellListView` – Remy Lebeau May 12 '23 at 16:11
  • i use viewstyle `Report` so yes the name will always in 1st column.. can you give example code to ignoring it ? – NettixCode May 13 '23 at 08:37
  • I already told you what you should change. I'm not going to actually write the code for you. – Remy Lebeau May 13 '23 at 17:11

0 Answers0