Thread Rating:
  • 344 Vote(s) - 2.8 Average
  • 1
  • 2
  • 3
  • 4
  • 5
グリッドへのドロップ
06-29-2016, 02:27 PM,
#1
グリッドへのドロップ
RecordGrid のレコードに何かアイテムをドラッグアンドドロップして処理をするにはどうすればよいですか?
また、その場合に、どのレコードにドロップ仕様としているのか、わかるようにしたいです。
06-29-2016, 02:33 PM,
#2
RE: グリッドへのドロップ
ドラッグ時にレコードの背景色を変更し、ドロップされたセルを取得し、ドロップされた行数を表示するサンプルです。
行挿入処理や、セルの値をGUIで指定することに利用できると思います。

Code:
{define-class public DoroppableListGrid {inherits RecordGrid}  {constructor public {default
                          record-source:#RecordSet = null,
                              sort:#RecordSort = null,
                              filter:#RecordFilter = null,
                              key-spec:any = null,
                              header-options:RecordGridRowOptions = {RecordGridRowOptions},
                              ui-object:#RecordGridUI = null,
                              ...
                      }
    {construct-super
        record-source = record-source,
            sort = sort,
            filter = filter,
            key-spec = key-spec,
            header-options = header-options,
            ui-object = ui-object,
           {splice ...}        ,
        {on e:DragOver at grid:RecordGrid do
            {e.will-accept-drop?
                {proc {type:Type, x:Distance, y:Distance,
                       effect:#DragEffect}:DragEffect                    def (cell:#RecordGridCell, record-index:int, column-index:int )= {grid.ui.grid-objects-at e.x, e.y}
                    set self.rollover-cell = cell                    {return drag-effect-copy}
                }
            }
        }
    }  }  {method public {on-drop e:Drop}:void
    {super.on-drop e}    ||ドロップイベントが完了したら、ロールオーバ色をリセットする
    set self.rollover-cell = null
  }
  field _rollover-cell:#RecordGridCell = null
  {setter private {rollover-cell cell:#RecordGridCell }    ||同一レコードの塗り直しは無視
    {if self._rollover-cell == cell then
        {return}
    }
    ||すでにロールバック色を塗ってある行を元に戻す
    {if-non-null self._rollover-cell , r = self._rollover-cell.record then        {for col in self.columns do
            {if-non-null c = {self.ui.get-cell-at r, col} then
                {if c.selected? then
                    set c.background = self.selected-background
                 else
                    {unset c.background}
                }
            }
        }    }    ||ロールバック色を設定する
    {if-non-null  cell ,  r = cell.record then        {for col in self.columns do
            {if-non-null c = {self.ui.get-cell-at r, col} then
                set  c.background = "orange"
                {output {c.get-data}}
            }
        }    }    set self._rollover-cell = cell  }}{define-proc public {notified rg:RecordGrid, r:Record, i:int}:#Background
    {if {r.compare-field "select", true} == 0 then
        {return  {Background.from-string "silver"}}
    else
        {return null}
    }
}
{let people:RecordSet =
    {RecordSet
        {RecordFields
            {RecordField "select", domain = bool,default-value = false},
            {RecordField "First", domain = String},
            {RecordField "Last", domain = String},
            {RecordField "Age", domain = int}
        },
        {RecordData First = "John", Last = "Smith", Age = 25},
        {RecordData First = "Jane", Last = "Smith", Age = 29, select = true},
        {RecordData First = "John", Last = "Smith", Age = 25, select = true},
        {RecordData First = "Jane", Last = "Smith", Age = 29},
        {RecordData First = "John", Last = "Smith", Age = 25, select = true},
        {RecordData First = "Jane", Last = "Smith", Age = 29},
        {RecordData First = "Jane", Last = "Smith", Age = 29},
        {RecordData First = "Jane", Last = "Smith", Age = 29},
        {RecordData First = "John", Last = "Smith", Age = 25, select = true},
        {RecordData First = "John", Last = "Smith", Age = 25, select = true},
        {RecordData First = "Jane", Last = "Smith", Age = 29},
        {RecordData First = "Jane", Last = "Smith", Age = 29},
        {RecordData First = "Jane", Last = "Smith", Age = 29},
        {RecordData First = "Jane", Last = "Jones", Age = 28}
    }
}
{value
    {DoroppableListGrid
        record-source = people        ,alternate-row-background = "#cceecc"        ,row-background-spec = notified        ,
        {on e:Drop at grid:RecordGrid do
            {e.accept-drop
                {proc {a:any, x:Distance, y:Distance,
                       effect:#DragEffect}:DropResult
                    {return {DropResultCopy
                                action = {proc {}:void
                                             def (cell:#RecordGridCell, record-index:int, column-index:int )= {grid.ui.grid-objects-at e.x, e.y}                                             {if-non-null cell then
                                                 {popup-message
                                                     cell.record-index + 1 &  "行目にドロップされました。",
                                                     modal? = true}
                                             }
                                         }
                            }
                    }
                }            }
        }
    }
}{def fr:Frame = {Frame border-width=1pt, "アイテム", dragee={ImageDragee}}}{value fr}




Forum Jump:


Users browsing this thread:
2 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('1368')