Thread Rating:
  • 323 Vote(s) - 2.9 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ListBox のアイテムをソートするには?
02-02-2014, 05:00 PM,
#2
RE: ListBox のアイテムをソートするには?
ちょうど同じようなことを試していたのでご参考までですが

ListBox.data-model にDefaultListModelが設定されている前提でDefaultListModel.sortメソッドを
使ってソートしたところ、表示内容も意図通りにソートされているように見えます。

(すでにお試しの方法で表示がおかしくなる条件があるのかもしれませんが ・・・)
下記のコードで試しています。

Code:
{define-proc {sort-string-data
                 lm:ListModel,
                 ascending?:bool = true
             }:void
    {type-switch lm
     case dlm:DefaultListModel do
        {dlm.sort
            comparison-proc =
                {proc {v1:any, v2:any}:bool
                    def s1 = v1 asa String
                    def s2 = v2 asa String
                    
                    def res = ({s1.compare s2} < 0)
                    
                    {if not ascending? then
                        {return (not res)}
                    }
                    {return res}
                }
        }
    }
}

{value
    def items = {new {Array-of String},
                    "Aardvark", "Cat", "Dog", "Elephant", "Gnu", "Zebra"
                }
    
    def lb =
        {ListBox
            selection-policy = "single",
            height = 30mm,
            width = 30mm,
            {splice items}
        }
    
    def lb-asc-cb = {CommandButton
                     label = "asc",
                     {on Action do
                         {sort-string-data
                             lb.data-model
                         }
                     }
                 }
    def lb-desc-cb = {CommandButton
                      label = "desc",
                      {on Action do
                          {sort-string-data
                              lb.data-model,
                              ascending? = false
                          }
                      }
                  }
    
    def dl =
        {DropdownList
            width = 30mm,
            {splice items}
        }
    
    def dl-asc-cb = {CommandButton
                     label = "asc",
                     {on Action do
                         {sort-string-data
                             dl.data-model
                         }
                     }
                 }
    def dl-desc-cb = {CommandButton
                      label = "desc",
                      {on Action do
                          {sort-string-data
                              dl.data-model,
                              ascending? = false
                          }
                      }
                  }
    
    {VBox
        spacing = 5mm,
        {VBox
            lb,
            {HBox
                spacing = 1mm,
                lb-asc-cb, lb-desc-cb
            }
        },
        {VBox
            dl,
            {HBox
                spacing = 1mm,
                dl-asc-cb, dl-desc-cb
            }
        }
    }
}


Messages In This Thread
RE: ListBox のアイテムをソートするには? - by dyoshida - 02-02-2014, 05:00 PM
Forum Jump:


Users browsing this thread:
1 Guest(s)

MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1017 - Can't find file: 'mybb_threadviews' (errno: 2)
Query:
INSERT INTO mybb_threadviews (tid) VALUES('1027')