Listbox Active Cell

  1. 4 years ago

    Dave S

    25 Jan 2015 San Diego, California USA

    I have a listbox where the cell is drawn with a colored background, with black text... this works
    But in the CELL Click event I want to "edit" the cell..... and this "kinda works"

    1. Listbox displays..... cell has proper background color... looks good
    2. User clicks on the cell, the background turns white.... NO FOCUS RING, NO CURSOR
    3. User clicks AGAIN.... now the FOCUS RING and CURSOR show up and the user can edit

    Why??

    Code in CELLCLICK

        If cellType(row,column)=listbox.TypeEditableTextField Then
          oldValue=cell(row,column)
          EditCell(row,column)
          ActiveCell.selstart=0
          ActiveCell.selstart=ActiveCell.Text.Len
          ActiveCell.SetFocus
        End If

    Also... isn't ESCAPE supposed to abort an edit???

  2. Karen A

    25 Jan 2015 Pre-Release Testers

    First I assume you want to edit the cell without first needing to select the row, which is why you are calling EditCell yourself. Normally the first click on an editable cell only selects the row if it's not already selected. if the row is selected clicking on a editable cell then initiates the edit without needing to call editcell.

    IIRC I usually set the ActiveCell properties in CellGotFocus and would return true after calling EditCell because I am handling initiating the edit.
    - Karen

  3. Will S

    25 Jan 2015 Santa Cruz 

    Does it reproduce in a new project? I tried your code out and it goes 1 to 3, step 2 never happens. Using a year old Xojo though.

  4. Dave S

    25 Jan 2015 San Diego, California USA

    @Will S Does it reproduce in a new project? I tried your code out and it goes 1 to 3, step 2 never happens. Using a year old Xojo though.

    not tried that, yet

    @Karen A First I assume you want to edit the cell without first needing to select the row, which is why you are calling EditCell yourself. Normally the first click on an editable cell only selects the row if it's not already selected. if the row is selected clicking on a editable cell then initiates the edit without needing to call editcell.

    IIRC I usually set the ActiveCell properties in CellGotFocus and would return true after calling EditCell because I am handling initiating the edit.
    - Karen

    If I move that piece of code to CELLGOTFOCUS...... it never actually edits the cell ..... it turns white.... but no cursor, no focus ring at all
    testing that showed, it selected the row, but never gave it "focus" [the 2nd click did that]

  5. Karen A

    25 Jan 2015 Pre-Release Testers
    Edited 4 years ago

    What I meant was in CellClick do:

    If cellType(row,column)=listbox.TypeEditableTextField Then
          oldValue=cell(row,column)
          EditCell(row,column)
          RETURN TRUE
        End If

    In CellGotFocus Do:

    me.ActiveCell.selstart=0 me.ActiveCell.selstart= me.ActiveCell.Text.Len

    Not sure what you are trying to do with setting the SelStart twice...

    If you want a black TextField with white text while editing, in CellGotfocus do

    me.ActiveCell.TextColor = &cFFFFFF00 me.ActiveCell.BackColor = &c00000000

  6. Dave S

    25 Jan 2015 San Diego, California USA
    Edited 4 years ago

    still have to double click to get a focusring/cursor...

    2nd selstart should have been sellength.... but taking it out made no diff.

    CellGotFocus does not fire until 2nd click :(

  7. Karen A

    25 Jan 2015 Pre-Release Testers

    @Dave S still have to double click to get a focusring/cursor...

    2nd selstart should have been sellength.... but taking it out made no diff.

    CellGotFocus does not fire until 2nd click :(

    Dave,

    Are you on Windows?

    My test code works fine on OSX.

    Here is my testing code directly from the IDE (current Xojo Version on OSX 10.9.5):

    Function CellClick(row as Integer, column as Integer, x as Integer, y as Integer) As Boolean
      me.EditCell(row,column)
      Return True
    End Function
    Sub CellGotFocus(row as Integer, column as Integer)
      me.ActiveCell.TextColor = &cFFFFFF00
      me.ActiveCell.BackColor = &c00000000
      'me.ActiveCell.selstart=0
      'me.ActiveCell.selstart= me.ActiveCell.Text.Len
     End Sub

    I'm not setting the cell to editable, but that should not matter

    - karen

  8. Tim H

    25 Jan 2015 Pre-Release Testers Portland, OR USA

    Note carefully the return true. Otherwise, the system keeps processing the click and undoes what you're trying to do.

  9. Dave S

    25 Jan 2015 San Diego, California USA

    Are you on Windows?

    Also on OSX

    @Tim H Note carefully the return true. Otherwise, the system keeps processing the click and undoes what you're trying to do.

    yes.. there is a RETURN TRUE in the CELLCLICK..... it is just outside of the IF/THEN... although I put one inside exactly as stated above, to no avail.

    1st click the cell changes color (indicating that it has gone "somewhere other" than CELLBACKGROUNDPAINT.... CELLTEXTPAINT is simply a "RETURN TRUE" statement)
    2nd click calls CELLGOTFOCUS

    The cell is set to be editiable at the time the listbox is populated (the number of rows doesn't change during the scope of the listbox)

  10. Dave S

    26 Jan 2015 San Diego, California USA

    well I cobbled up a tiny project with just a listbox.... and of course... IT WORKS....

    so there is something in my other app that I can't find. I had put msgs everywhere....
    It SAYS it is calling EDITCELL on the first click.... but it is like something is moving it, and the 2nd click makes it "stay"

    This is getting quite frustrating, and I don't have enough hair left to be pulling anymore out :D

  11. Dave S

    26 Jan 2015 San Diego, California USA

    Interesting sequence of events however....

    1. MouseDown Event
    2. Called EDITCELL
    3. repaints cell (without calling CELLBACKGROUNDPAINT...... how is this possible)
    4. Click Mouse 2nd Time
    5. CELLGOTFOCUS
    6. THEN 2nd MouseDown Event (would have thought MD would happen first)

    My CellBackgroundPaint NEVER paints a white cell, just Step #3 above DOES

  12. Dave S

    26 Jan 2015 San Diego, California USA

    Ok.... NOW I AM REALLY CONFUSED.

    In BOTH the CELLBACKGROUNDPAINT and CELLTEXTPAINT events... I have a single line

    RETURN TRUE

    Yet it STILL draws a GRAY FILLED box whenever I click on the Listbox..... How can that be?
    I've turned OFF all drawing events (haven't I?)

  13. Dave S

    26 Jan 2015 San Diego, California USA

    Ok... (totally bald now :) )..... I managed somehow to get the drawing to come out correctly........

    BUT I still can't get ACTIVECELL to have the focus when EDITCELL is called..... it is as if something is "stealing" the focus the split second ActiveCell gets it.... but I have put breakpoints on every single SETFOCUS command in the program and none of them are hit

    And it seems impossible to tell where the focus has gone.... .

    I even added my own textfield in place of ActiveCell... and it indicates it never GETS the focus, despite an explict command to do so

  14. Dave S

    27 Jan 2015 San Diego, California USA

    Well I think I solved it ....

    seems the issue was the fact the the parent window was a "FLOATING" window... so the focus was flying all over the place.
    Made it a "document" window and the ActiveCell now works as expected..... this however introduced other problems that I now have to deal with

or Sign Up to reply!