Forum: FXRuby Scrolling to the newly appended row in an FXTable

0157def628fa9a2d7dbd44a1f26f8f3e?d=identicon&s=25 Philippe Lang (Guest)
on 2007-10-12 11:44
(Received via mailing list)
Hi,

After appending a row in an FXTable, I'd like to scroll the FXTable to
the last line of the FXTable, to make sure the new row is visible.

I'm using this kind of code:

  def onInsertRow(sender, sel, ptr)
    @table.appendRows(1, true)
    @table.setPosition(0, -1000) # I never have more that 1000 lines
in the table!
  end

The problem is that I'm unable to scroll until the last line, only the
line *** before the last line ***. Apparently, it's a "timing" problem:
when position is set, the line append is not completely "committed" to
the GUI.

Called separately, @table.setPosition(0, -1000) works just fine, as you
can see in this test:

------------------

#!/usr/bin/env ruby

require 'fox16'
require 'date'

include Fox

class TableWindow < FXMainWindow

  def initialize(app)
    # Call the base class initializer first
    super(app, "Table Widget Test", :opts => DECOR_ALL)

    # Tooltip
    tooltip = FXToolTip.new(getApp())

    # Menubar
    menubar = FXMenuBar.new(self, LAYOUT_SIDE_TOP|LAYOUT_FILL_X)

    # Separator
    FXHorizontalSeparator.new(self,
LAYOUT_SIDE_TOP|LAYOUT_FILL_X|SEPARATOR_GROOVE)

    # Contents
    contents = FXVerticalFrame.new(self,
LAYOUT_SIDE_TOP|FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y)

    frame = FXVerticalFrame.new(contents,
      FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y, :padding =>
0)

    # Table
    @table = FXTable.new(frame,
      :opts =>
TABLE_COL_SIZABLE|TABLE_ROW_SIZABLE|LAYOUT_FILL_X|LAYOUT_FILL_Y,
      :padding => 2)

    @table.visibleRows = 10
    @table.visibleColumns = 4

    @table.setTableSize(20, 14)

    # Initialize column headers
    (0...12).each  { |c| @table.setColumnText(c, Date::MONTHNAMES[c+1])
}

    # Initialize row headers
    (0...20).each { |r| @table.setRowText(r, "Row#{r}") }

    # File Menu
    filemenu = FXMenuPane.new(self)
    FXMenuCommand.new(filemenu, "&Quit\tCtl-Q", nil, getApp(),
FXApp::ID_QUIT)
    FXMenuTitle.new(menubar, "&File", nil, filemenu)

    # Manipulations Menu
    manipmenu = FXMenuPane.new(self)

    FXMenuCommand.new(manipmenu, "Insert Row").connect(SEL_COMMAND,
method(:onInsertRow))
    FXMenuCommand.new(manipmenu, "Go to last row").connect(SEL_COMMAND,
method(:onCmdGoToLastRow))

    FXMenuTitle.new(menubar, "&Manipulations", nil, manipmenu)

  end

  def onCmdGoToLastRow(sender, sel, ptr)
    @table.setPosition(0, -1000)
  end

  def onInsertRow(sender, sel, ptr)
    @table.appendRows(1, true)
    @table.setPosition(0, -1000)
  end

  # Create and show this window
  def create
    super
    show(PLACEMENT_SCREEN)
  end
end

# Start the whole thing
if __FILE__ == $0
  # Make application
  application = FXApp.new("TableApp", "FoxTest")

  # Make window
  TableWindow.new(application)

  # Create app
  application.create

  # Run
  application.run
end

------------------

Any idea how I can do that?

Thanks!

Philippe Lang
5b972395a92333843018b4add8af0437?d=identicon&s=25 Damián M. González (igorjorobus)
on 2012-12-12 13:36
You have to call after appends the row:

 @table.create
 @table.recalc
 @table.layout

 Then you have to go to the new position.
This topic is locked and can not be replied to.