Thread Rating:
  • 554 Vote(s) - 2.76 Average
  • 1
  • 2
  • 3
  • 4
  • 5
レコードの挿入で一番上の行が選択されてしまう
05-24-2013, 08:12 PM,
#1
レコードの挿入で一番上の行が選択されてしまう
レコードの挿入をするために、インデックスをつけて、選択されている行に追加したレコードが表示されるようにソートしています。

しかし、なぜか、レコードの一番上の行が選択されてしまいます。
batch-events? を利用しないと、現在の選択はそのままとなるのですが、
それだと、レコードの追加に時間がかかってしまいます。

現在のレコードの選択状態を変えないままレコードを挿入するには
どうすればよいでしょうか。

Code:
{let rs:RecordSet =
    {RecordSet
        {RecordFields
            {RecordField "index", domain = int},
            {RecordField "First", domain = String},
            {RecordField "Last", domain = String},
            {RecordField "Age", domain = int}
        }
    }
}
{for i:int = 0 to 100 do
    def rd = {RecordData}
    set rd["index"] = i + 1
    {rs.append rd}
}
{def grid =
    {RecordGrid
        sort = "index",
        record-source = rs
    }
}
{value grid}
{CommandButton
    {on Action do
        let insert-index:int = rs.size
        {if grid.current-index > -1 then
            set insert-index = grid.current-index + 1
        }

        def new-r = {RecordData}|| {rs.new-record}
        set new-r["index"] = insert-index

        ||batch-events? を使うと一番上のレコードが選択されてしまう
        {with rs.batch-events? = true do
            ||挿入のために、対象インデックス以降を+1
            {for r in rs do
                {if r["index"] asa int >= insert-index then
                    set r["index"] = r["index"] asa int + 1
                }
            }
        }
        {rs.append new-r}
        
        ||下記コードで、元の選択状態に戻せるが
        ||画面がちらついたり、スクロール位置が変わるのが問題
||++    {after 0s do
||++        {grid.select-record insert-index}
||++        set grid.current-index = insert-index
||++    }
    }
}


Messages In This Thread
レコードの挿入で一番上の行が選択されてしまう - by umemura - 05-24-2013, 08:12 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('902')