How to "short-circuit" an event? 
Author Message
 How to "short-circuit" an event?

I would like to know how to "short-circuit" (I don't know if it has a
meaning in English because I'm French; maybe the right word is "break") the
change event in a listbox.

In fact, I have a listbox with 3 columns which 2 of them are editable. I
would like the text of their cells to be exactly 4 caracters in length after
the user edited it.

I had many problems in trying to make that. I can publish the code, if you
want. The only way I found to solve these problems is to "short-circuit" the
change event. But I don't know how to do...

PS: Excuse me, my English is very poor.



Sun, 19 Sep 2004 04:11:44 GMT  
 How to "short-circuit" an event?

Quote:

> In fact, I have a listbox with 3 columns which 2 of them are editable. I
> would like the text of their cells to be exactly 4 caracters in length after
> the user edited it.

in CellTextChange you may correct the text if you want.

Mfg
Christian

--
Kostenlose MacOS und Win95/98/NT Programme unter

http://www.christians-software.de



Sun, 19 Sep 2004 07:03:52 GMT  
 How to "short-circuit" an event?
I would like to know how to "short-circuit" (I don't know if it has a
meaning in English because I'm French; maybe the right word is "break") the
change event in a listbox.

In fact, I have a listbox with 3 columns which 2 of them are editable. I
would like the text of their cells to be exactly 4 caracters in length after
the user edited it.

I had many problems in trying to make that. I can publish the code, if you
want. The only way I found to solve these problems is to "short-circuit" the
change event. But I don't know how to do...

PS: Excuse me, my English is very poor.



Mon, 20 Sep 2004 01:17:50 GMT  
 How to "short-circuit" an event?
Oops! Excuse me for the precedent message. I sent the wrong one.

Quote:


>> In fact, I have a listbox with 3 columns which 2 of them are editable. I
>> would like the text of their cells to be exactly 4 caracters in length after
>> the user edited it.

> in CellTextChange you may correct the text if you want.

I can limit the length of the text to 4 carcters, but I want the text to be
at least 4 caracters in length after the user edited it, too.

When I said I wanted to "short-circuit" the change event, I mean I wanted an
equivalent of the "cancelclose" event for windows. I would like to create a
"cancelchange" event. That could be possible with the Mac OS ToolBox...

Quote:
> Mfg
> Christian

> --
> Kostenlose MacOS und Win95/98/NT Programme unter

> http://www.christians-software.de



Mon, 20 Sep 2004 01:36:06 GMT  
 How to "short-circuit" an event?
So what you want is the ability to reject the change if you don't like
what the user typed. Seems to me that you could save the old contents
of the cell in a property of the window then on the CellAction event
see if you approve the change. If you do, copy the cell contents to
the "old value" property. If you don't like the change, copy the "old
value" back into the cell and the user's change disappears.

Steve

Quote:

> Oops! Excuse me for the precedent message. I sent the wrong one.


> >> In fact, I have a listbox with 3 columns which 2 of them are editable. I
> >> would like the text of their cells to be exactly 4 caracters in length after
> >> the user edited it.

> > in CellTextChange you may correct the text if you want.



Wed, 22 Sep 2004 03:49:59 GMT  
 How to "short-circuit" an event?

Quote:
> So what you want is the ability to reject the change if you don't like
> what the user typed. Seems to me that you could save the old contents
> of the cell in a property of the window then on the CellAction event
> see if you approve the change. If you do, copy the cell contents to
> the "old value" property. If you don't like the change, copy the "old
> value" back into the cell and the user's change disappears.

> Steve

Yes. That's what I done (not exactly, but what I've done is similar). But it

The listbox hold 3 columns. The 2nd and the 3rd are editable (number 1 and
2, so).

In the "Open" event of the listbox:

  listBox1.columnType(1)=3 //make the cells of the 2nd column editable
  listBox1.columnType(2)=3 //make the cells of the 3rd column editable
  erreur=false //see after...

In the "CellLostFocus" event of the listbox (as soon as the user clicks
elsewer):

    if len(listBox1.cell(row,column))<>4 then //if the text isn't 4
caracters in lenght...
    beep
    erreur=true //there is an error with the cell which lost the focus...
    colonne=column //write the number of the column of the cell which lost
the focus in the property "colonne"
    ligne=row //write the number of the row of the cell which lost the focus
in the property "ligne"
  end if

Now, in the "change" event (I want the selected cell to be the one which
previously lost the focus):

     if erreur=true then //to know if the text of the previously selected
cell had a length different from 4 caracters
    listBox1.editCell(ligne,colonne) //select the previously selected cell
    listBox1.activeCell.selstart=len(listBox1.activeCell.text) //put the
cursor to the end of the text
    erreur=false //reinitialisation of "erreur"
  end if

Try this code. There is a problem: when the user clicks outside of the cell
he was editing and if the length of text of this cell is different from 4
caracters, he can hear the beep, but then the cell takes the text of the
cell where he clicked (that seems complicated, but try it, you'll understand
immediatly).

So I modified my code:

In "CellLostFocus":

  if len(listBox1.cell(row,column))<>4 then
    beep
    erreur=true
    if column=1 then
      typetext=listBox1.cell(row,column) //Copy the text of the cell which
lost the focus if the cell was in the 2nd column in the property "typetext".
    elseif column=2 then
      creatortext=listBox1.cell(row,column) //Copy the text of the cell
which lost the focus if the cell was in the 3rd column in the property
"creatortext".
    end if
    colonne=column
    ligne=row
    listBox1.columnType(1)=1 //makes all the cells of the 2nd column
uneditable (temporarily) in order to solve the problem cited
    listBox1.columnType(2)=1 //ditto for the 3rd column
  end if

In "Change":

  if erreur=true then
    listBox1.columnType(1)=1
    listBox1.columnType(2)=1
    listBox1.editCell(ligne,colonne)
    if colonne=1 then
      listBox1.Cell(ligne,colonne)=typetext //Paste the text of the cell
which lost the focus if the cell is in the 2nd column.
    elseif colonne=2 then
      listBox1.Cell(ligne,colonne)=creatortext //Paste the text of the cell
which lost the focus if the cell in in the 3rd column.
    end if
    listBox1.activeCell.selstart=len(listBox1.activeCell.text)
    erreur=false
    listBox1.columnType(1)=3//makes all the cells of the 2nd column editable
again
    listBox1.columnType(2)=3 //ditto for the 3rd column
  end if

That works sometimes and sometimes not. In fact, the text of the cell which
lost the focus becomes the text of the one where the user clicked only if
the latter has been previously edited. Moreover, in this case, the cursor
becomes the cursor of text edition when it pass over a cell different from
the one the user is editing and if this one has been already edited.
But I don't understand why... Maybe it's a bug.

It could seem difficult to understand (because I don't speak English very
well), but try it, you'll understand immediatly.



Wed, 22 Sep 2004 17:50:45 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Getting "Short" filenames inWindows

2. string.join(["Tk 4.2p2", "Python 1.4", "Win32", "free"], "for")

3. BEGIN{want[]={"s1o", "s2o", "s2q", "s3q"}

4. Where do Events "live"

5. News Selection event "delayed"?

6. Xilinx Vhdl "'event" synthesis problem

7. instance creatiion as an "event"

8. upvar and "event driven"

9. Strange "event genrate" behavior

10. Question about "event generate"

11. Events as a "control mechanism"

12. instance creatiion as an "event"

 

 
Powered by phpBB® Forum Software