ListViewGetContent with option "Col4" fails with Column 1 (displays Col1 and Col2 in test code)

Issue #62 closed
Winter Laite created an issue

Issue

ListViewGetContent has 7 options. Option styled “Col4” in the docs [per docs replace '4' with desired #] fails if Col 1 is selected.

steps to duplicate

Run code below with Keysharp.

MyGui := Gui()

LV2_Label := MyGui.Add("Text", "w400 x10 y10","ListView testing")
LV2_Label.SetFont("cBlue s10")
; Create the ListView with two columns, Name and Size:
LV2 := MyGui.Add("ListView", "r15 w350 x10 y+5", ["Name","Size (KB)"])

Loop Files, A_MyDocuments "\*.*"
  LV2.Add(, A_LoopFileName, A_LoopFileSizeKB)


LV2_Btn3 := MyGui.Add("Button", "x10 y+10", "Column 1")
LV2_Btn3.OnEvent("Click", "LV_Col1")


MyGui.Show()



LV_Col1() {
    List := ListViewGetContent("Col1", LV2, MyGui)
    MsgBox(List, "LV Column 1")
    List := ""
}

Note that both Col1 and Col2 are displayed. (Replace “Col1” with “Col2” in Line 21 to see no failure if Col2 is selected).

AHk verification code
MyGui := Gui()

LV2_Label := MyGui.Add("Text", "w400 x10 y10","ListView testing")
LV2_Label.SetFont("cBlue s10")
; Create the ListView with two columns, Name and Size:
LV2 := MyGui.Add("ListView", "r15 w350 x10 y+5", ["Name","Size (KB)"])

Loop Files, A_MyDocuments "\*.*"
  LV2.Add(, A_LoopFileName, A_LoopFileSizeKB)


LV2_Btn3 := MyGui.Add("Button", "x10 y+10", "Column 1")
LV2_Btn3.OnEvent("Click", LV_Col1)


MyGui.Show()


LV_Col1(*) {
    List := ListViewGetContent("Col1", LV2, MyGui)
    MsgBox(List, "LV Column 1")
    List := ""
}

Comments (6)

  1. Winter Laite reporter

    I ran dnSpy on Keysharp to try to find the code for “Count Col”. Examining the source code of Keysharp.Core.Windows.ControlManager, I’ve been unable to find the code that resulted in this listing from dnSpy:

                                    else
                                    {
                                        bool flag7 = Options.TryParse(opt, "col", ref col, StringComparison.OrdinalIgnoreCase, false, 0);
                                        if (flag7)
                                        {
                                            int col2 = col;
                                            col = col2 - 1;
                                        }
                                    }
    

    However, if this is an accurate representation of what the code is doing, it appears that if ‘col’ is equal to 1, then col2 will also equal 1. ‘col’ is then assigned col2-1, or 1-1, or 0, resulting in a display of all columns, which is the failure with number of columns set to '1'.

  2. Winter Laite reporter

    It may be that a starting point would be line 954 in Keysharp.Core.Windows.ControlManager:

                        else if (Options.TryParse(opt, "col", ref col)) { col--; }
    

    If ‘col’ == 1, then after operation col would be 0, if I’m not mistaken, and all columns would be shown.

  3. Log in to comment