From: Alan Grunwald on
Hi,

I'm trying to get a tablelist to expand automatically. I.e. if you
enter some data in the bottom-right hand cell and press tab, then I
would like to insert an additional row at the bottom of the table and
start to edit the first cell of the new row.

I can do this, but in addition, if you complete the edit of the last
cell by pressing return, I just want to insert the new row.

How can I determine from within my -editendcommand proc whether the
user finished the edit by pressing tab or return?

Many thanks,
Alan
From: Csaba Nemethi on
Am 07.07.2010 20:12, schrieb Alan Grunwald:
> Hi,
>
> I'm trying to get a tablelist to expand automatically. I.e. if you
> enter some data in the bottom-right hand cell and press tab, then I
> would like to insert an additional row at the bottom of the table and
> start to edit the first cell of the new row.
>
> I can do this, but in addition, if you complete the edit of the last
> cell by pressing return, I just want to insert the new row.
>
> How can I determine from within my -editendcommand proc whether the
> user finished the edit by pressing tab or return?
>
> Many thanks,
> Alan

Here is one way to achieve this:

$tbl configure -forceeditendcommand 1 -editstartcommand editStartCmd \
-editendcommand editEndCmd
set editWinTag [$tbl editwintag]
bind $editWinTag <Tab> {set pressedKey Tab}
bind $editWinTag <Return> {set pressedKey Return}

proc editStartCmd {tbl row col text} {
# Reset the pressed key
set ::pressedKey "dontcare"
. . .
}

proc editEndCmd {tbl row col text} {
if {$row == [$tbl size] - 1 && $col == [$tbl columncount] - 1} {
if {$::pressedKey eq "Tab" || $::pressedKey eq "Return"} {
# Append a new row
. . .
}
if {$::pressedKey eq "Tab"} {
after 50 [list $tbl editcell end,0]
}
}

. . .
}

There are still some possible improvements that could be added. For
example, the script passed to "after 50" could be a procedure that not
only invokes the editcell subcommand, but also moves the selection to
the newly inserted last row.

--
Csaba Nemethi http://www.nemethi.de mailto:csaba.nemethi(a)t-online.de

From: Alan Grunwald on
Csaba Nemethi wrote:
> Am 07.07.2010 20:12, schrieb Alan Grunwald:
>> Hi,
>>
>> I'm trying to get a tablelist to expand automatically. I.e. if you
>> enter some data in the bottom-right hand cell and press tab, then I
>> would like to insert an additional row at the bottom of the table and
>> start to edit the first cell of the new row.
>>
>> I can do this, but in addition, if you complete the edit of the last
>> cell by pressing return, I just want to insert the new row.
>>
>> How can I determine from within my -editendcommand proc whether the
>> user finished the edit by pressing tab or return?
>>
>> Many thanks,
>> Alan
>
> Here is one way to achieve this:
>
> $tbl configure -forceeditendcommand 1 -editstartcommand editStartCmd \
> -editendcommand editEndCmd
> set editWinTag [$tbl editwintag]
> bind $editWinTag <Tab> {set pressedKey Tab}
> bind $editWinTag <Return> {set pressedKey Return}
>
> proc editStartCmd {tbl row col text} {
> # Reset the pressed key
> set ::pressedKey "dontcare"
> . . .
> }
>
> proc editEndCmd {tbl row col text} {
> if {$row == [$tbl size] - 1 && $col == [$tbl columncount] - 1} {
> if {$::pressedKey eq "Tab" || $::pressedKey eq "Return"} {
> # Append a new row
> . . .
> }
> if {$::pressedKey eq "Tab"} {
> after 50 [list $tbl editcell end,0]
> }
> }
>
> . . .
> }
>
> There are still some possible improvements that could be added. For
> example, the script passed to "after 50" could be a procedure that not
> only invokes the editcell subcommand, but also moves the selection to
> the newly inserted last row.
>

Thanks Csaba,

--
Alan