On Dec 28, 2005, at 3:25 PM, Chuck Pelto wrote:


On Dec 27, 2005, at 11:41 AM, CV wrote:

On Dec 27, 2005, at 8:05 AM, Chuck Pelto wrote:

Is this possible? And how can I change the text in a listbox cell without going through the system in the examples?

Yes. Write code in CellKeyDown to identify navigation keys and use EditCell. The snippet below is an example of the type of code that might be used, perhaps in a subclass of listbox. It was for a two column box.

If key = chr(9) or key = chr(29) or key = chr(13) then 'tab key, right arrow, return
    'move to next available entry cell
    If column + 1 <= me.columnCount - 1 then 'tab to next column
      me.editCell row,column + 1
Elseif row + 1 <= me.listcount - 1 then 'currently in last column, not about to exit
      if column - 1 >= 0 then  'not in column 0 (must be in column 1)
        If me.Cell(Row, 0) <> "" then 'if a variable name is entered
          If me.Cell(Row,1) = "" then 'but no value, then
            beep
            msgBox "Please enter a value or delete the variable."
            me.EditCell Row, 1
          Else
me.editCell row+1, column - 1 'advance one row, to column 0
          End if
        Else
me.editCell row + 1, column - 1 'advance one row, to column 0
        End if
      End if
Elseif row + 1 > me.listcount - 1 then 'attempting to exit list, so go back to start
      me.editCell StartEditableRow,0
    End if
    return true
  End if

I've established something akin to this. Here's the code in the CellKeyDown event of the listbox in question:

  dim nextCol as integer

  // if key down is TAB go to next cell in row

  if key = chr(9) or key = chr(29) then

    if column < listBox1.ColumnCount then

      nextCol = column + 1

      me.EditCell(row, nextCol)

    elseif column = istBox1.ColumnCount then

      me.EditCell(row, 1)

    end if

  end if

Unfortunately, it does not seem to want to move the focus in the listbox from one cell to the next.

Instead, what is happening is no matter what key is pressed, while in the cell, it takes the focus to the next object in the window. In this instance an edit field at the top of the page; as the listbox is the last item on the page.

What's going on here? How is it fixed?

Also, let me offer a coding suggestion -- you can replace the comment by some actual code.

dim TAB as String = Encodings.UTF8.Chr(9)
dim RightArrow as String = Encodings.UTF8.Chr(29)
 if key = TAB or key = RightArrow then

etc.

Note that this reveals that the comment isn't quite correct. This may seem trivial, but such details do add up.

Furthermore, since TAB and RightArrow are the same for all instances, you can use a static variable and feel more efficient --

static TAB as String = Encodings.UTF8.Chr(9)
static RightArrow as String = Encodings.UTF8.Chr(29)
 if key = TAB or key = RightArrow then


--------------
Charles Yeomans

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to