Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there an equivalent of "AfterRowColChange" in Listbox control? 1

Rajesh Karunakaran

Programmer
Joined
Sep 29, 2016
Messages
561
Location
MU
Hi Friends,

I have a list box whose RowSource is a cursor.
Is there an event in Listbox control equivalent to the "AfterRowColChange" event of a Grid control ?

My requirement is to show the value from the current record in a textbox below the listbox as the user go un and down in the listbox.

Thanks in advance
 
Hi Joe,

Yes, it's working!
Opps! my mistake. I knew, I saw it also but didn't try it before posting here 🤦‍♀️

Thanks
 
Hi,

To illustrate Joe's answer, please have a look a the code below

Code:
PUBLIC go_Form

go_Form=CREATEOBJECT("clsForm")
go_Form.Visible = .T.
go_Form.Show()

READ Events


CLOSE ALL
CLEAR ALL

************

DEFINE CLASS clsForm as Form

    AutoCenter = .T.
    Width = 420
    MinWidth = 420
    MaxWidth = 420
    Height = 360
    MinHeight = 360
    MaxHeight = 360
    ShowTips = .T.
   
   
    ADD OBJECT lblLabel as Label WITH Top = 6, Left = 6, Autosize = .T., ;
                Caption = "Name", Anchor = 3

    ADD OBJECT txtName as TextBox WITH Top = 30, Left = 258, Width = 90, Height = 24, ReadOnly = .T., Anchor = 3, ;
        DisabledBackColor = RGB(250, 250, 250), ToolTipText = "Name"

    ADD OBJECT txtNumber as TextBox WITH Top = 60, Left = 258, Width = 90, Height = 24, ReadOnly = .T., Anchor = 3, ;
        Alignment = 1, DisabledBackColor = RGB(250, 250, 250), ToolTipText = "ID"                                  
   
    ADD OBJECT txtGender as TextBox WITH Top = 90, Left = 258, Width = 90, Height = 24, ReadOnly = .T., Anchor = 3, ;
        DisabledBackColor = RGB(250, 250, 250), ToolTipText = "Gender"

    ADD OBJECT txtHeight as TextBox WITH Top = 120, Left = 258, Width = 90, Height = 24, ReadOnly = .T., Anchor = 3, ;
        DisabledBackColor = RGB(250, 250, 250), Alignment = 1, ToolTipText = "Height"

    ADD OBJECT cboBox as ComboBox WITH Top = 30, Left = 6, Width = 240, Height = 24, ;
            RowSourceType = 2, RowSource = "csrEmployees", Style = 2, Sorted = .T., ;
            Anchor = 3, ToolTipText = "Type name or click down arrow"
           
        PROCEDURE cboBox.Init()
            This.Value = csrEmployees.cName
           
            WITH ThisForm
                .txtName.Value = csrEmployees.cName
                .txtNumber.Value = csrEmployees.iNumber
                .txtGender.Value = csrEmployees.cGender
                .txtHeight.Value = csrEmployees.nHeight
            ENDWITH
           
            This.SetFocus()                

        ENDPROC
       
*!*    START of procedure that feeds the TextBoxes with their values

        PROCEDURE cboBox.Click()
       
            WITH ThisForm
                .txtName.Value = csrEmployees.cName
                .txtNumber.Value = csrEmployees.iNumber
                .txtGender.Value = csrEmployees.cGender
                .txtHeight.Value = csrEmployees.nHeight
            ENDWITH
       
        ENDPROC

*!*    END of the feeding procedure
   
        PROCEDURE cboBox.InterActiveChange()
       
            This.Click()
           
        ENDPROC

    PROCEDURE Load()
        CREATE CURSOR csrNames (cName c(8),iNumber I, cGender c(1), nHeight N(5,2))
       
        INSERT INTO csrNames VALUES ('Karl', 123, 'M', 1.75)
        INSERT INTO csrNames VALUES ('Robert', 124, 'M', 1.80)
        INSERT INTO csrNames VALUES ('Luisa', 125, 'F', 1.70)
        INSERT INTO csrNames VALUES ('Megan', 126, 'F', 1.68)
        INSERT INTO csrNames VALUES ('Georges', 127, 'M', 1.82)
        INSERT INTO csrNames VALUES ('Kim', 128, 'F', 1.65)
        INSERT INTO csrNames VALUES ('Paul', 129, 'M', 1.85)
        INSERT INTO csrNames VALUES ('Corinne', 130, 'F', 1.54)
        INSERT INTO csrNames VALUES ('Elisa', 131, 'F', 1.68)
        INSERT INTO csrNames VALUES ('John', 132, 'M', 1.72)
        INSERT INTO csrNames VALUES ('Frank', 133, 'M', 1.90)
       
        SELECT * FROM csrNames ORDER BY 1 INTO CURSOR csrEmployees      
    ENDPROC

    PROCEDURE Destroy()
        USE
        ThisForm.Release
        CLEAR Events
   
    ENDPROC
ENDDEFINE

************

hth

MarK
 
The grid has an active row, always one is a current row with the record pointer on it. The listbox has selected items, there can also be none selected or you can have multiselect, those are totally different concepts. The grid also has no value, neither single nor multiple in the sense there's a controlsource for twoway binding, every cell is a textbox with single value binding, but depends what control you put in a grid cell. The grid is always "binding" all it's cells to how many records and fields/columns the recordsource has or the grid has defined.

Well, good that InteractiveChange works for your case. It's not really something equivalent. InteractiveChange is about the change of value, which the grid kind of has not at all or for every cell, however you look at it.
 
Last edited:
For the record, InteractiveChange isn't the same as AfterRowColChange because it's only triggered when the control is changed, not when a row changes, but in your case, you said you wanted it to trigger when the user scrolled the values in the control.

The nice benefit of this is that those values aren't dependent on a row in a cursor.

Just remember the initial value will not trigger it unless you implicitly call it when the form loads.
 
Good points, Joe.

There's always a current "active" row in a workarea, independent of controls. And some controls actually only care about that row. Grid and Listbox also display other rows. And Listbox and Grid also have in common if you click on a cell or item that changes the current active row in the workarea. too. There's nno inverse, i.e. GO SKIP, SEEK or LOCATE to chenge record in a workarea doesn't make these the current value of a listbox and the grid doesn't even need to automatically scroll to that place, the active grid row can be off the visible area. And the grids AfterRowColChange only happens after the user interactively switches to another row or column, it doesn't occur for using the scrollbar, neither so in the listbox.

In short you don't have any thinkable ecvent that could be considerable to detect something, sometimes record specific events would be a nice thing to have. It could also open a can of worms of cascades of events just because you do a SCAN loop or you change record in an event and trigger it all over again. Surely a reason the VFP dev team didn't implement events like that.
 

Part and Inventory Search

Sponsor

Back
Top