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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

the list

Status
Not open for further replies.
Hi,
For this you check 'Solutions' and look for Controls where you select Listbox.

Solutions.app you will find in HOME(2) directory.

Regards,

Koen
 
Hi,
You may want to have a look at the code below

Code:
PUBLIC go_Form

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

READ Events
CLOSE ALL 
CLEAR ALL 


DEFINE CLASS MyForm as Form
	AutoCenter = .T.
	Width = 420
	MinWidth = 420
	Height = 360
	MinHeight = 360
	
	ADD OBJECT cboBox as ComboBox WITH Top = 30, Left = 6, Width = 240, ; 
			ColumnCount = 2, ColumnWidths = '125, 75', RowSourceType = 2, RowSource = "csrNames", Style = 2, Sorted = .T., ;
			Anchor = 3

	ADD OBJECT txtName as TextBox WITH Top = 30, Left = 258, Width = 120, Height = 24, ReadOnly = .T., Anchor = 11
	ADD OBJECT txtNumber as TextBox WITH Top = 60, Left = 258, Width = 120, Height = 24, ReadOnly = .T., Anchor = 11
	
	ADD OBJECT lblLabel as Label WITH Top = 6, Left = 6, Autosize = .T., ;
				Caption = "Please type a letter or open the drop-down", Anchor = 3

	PROCEDURE cboBox.Click()
		WITH ThisForm
			.txtName.Value = ThisForm.cboBox.List(ThisForm.cboBox.Listindex,1)
			.txtNumber.Value = ThisForm.cboBox.List(ThisForm.cboBox.Listindex,2)
		ENDWITH 
	
	ENDPROC 
	
	PROCEDURE cboBox.InterActiveChange()
		This.Click()
	
	ENDPROC 
	
	PROCEDURE Load()
		CREATE CURSOR csrNames (cName c(8),iNumber I)
		INSERT INTO csrNames VALUES ('Karl', 123)
		INSERT INTO csrNames VALUES ('Robert', 124)
		INSERT INTO csrNames VALUES ('Luisa', 125)
		INSERT INTO csrNames VALUES ('Megan', 126)
		INSERT INTO csrNames VALUES ('Georges', 127)
		INSERT INTO csrNames VALUES ('Kim', 128)
		INSERT INTO csrNames VALUES ('Paul', 129)
		INSERT INTO csrNames VALUES ('Carmen', 130)
		INSERT INTO csrNames VALUES ('Elisa', 131)
		INSERT INTO csrNames VALUES ('John', 132)
		INSERT INTO csrNames VALUES ('Frank', 133)
		
	ENDPROC
	
	PROCEDURE Destroy()
		USE
		CLEAR Events
		ThisForm.Release
	
	ENDPROC
	
ENDDEFINE

hth
MK
 
I explained a few things about the combobox here:

myself said:
The Combobox is bringing two tables together in the normal case. In the special case, you might only use a Combobox with a variable or property as ControlSource and use it to get a name or other display value, not an ID.

[...]

ControlSource
...the most important fact about the ControlSource is, it's not only source but also the target. It's the field you want to modify with a form control and it initializes it, as the control should show it to the user and the best way to achieve that is that it's the displayed data source, thus the name of that property.

The only control differing from that idea about the Controlsource is the grid There the RecordSource is also the ControlSource. Also a reason its name differs from RowSource. The naming of all three was well chosen by the VFP developers, they all have different purposes. But like in a textbox or edit box ControlSource is the field from which the first display value comes from and where the edited value goes back to.

Now a thing you never can change is what a Combobox (Also a listbox) displays in first place, that's the first column of RowSource. Therefore, as in mjcmkrsr example, you can use a RowSource cursor with two fields NAME and ID in that order, or use a normal table with an ID as the first column and make use of RowSourceType 6 (fields) to switch the field order in the best way to have the display value in the first column. That's the only thing I'd change in that example, so it works with data structured the usual way with ID first.

That's already the hardest lesson to learn. The rest just follows, if you attentively read about the meaning of Value in case of combobox/listbox in conjunction with BoundTo and BoundColumn. Pay attention what is said about the behavior depending on the data type, especially when you set BoundTo=.F., as it most often should be used:

VFP help topic "BoundTo" said:
(Default) The Value property is determined by the data type of the variable or field specified in the ControlSource property.

If the variable or field specified in the ControlSource property setting is of character type, the Value property is determined by the List property.

If the variable or field specified in the ControlSource property setting is of numeric type, the Value property uses the index number from the ListIndex property.

This setting provides compatibility with Microsoft Visual FoxPro 3.0 and 2.x versions of FoxPro.

That's a bit counterintuitive, as you would think you best set BoundTo=.T. and BoundColumn=2, instead you leave BoundTo=.F. and BoundColumn=2.

It's a bit convoluted by the history of the control and when and how and why things were added with their behavior.

The listbox has another difficulty level with multiselect. You don't get that with cursor (or alias) RowSourceType as there is only one current record in a workarea. The multiple selections in a listbox only get clear from watching values of listindex while deselecting one item after the other. You only can scan the Selected array when the listbox is array based or items are added with AddItem() instead of data binding. Not only important, if you want to use Multiselect and Selected but also MoverBars.

There are rather nontechnical reasons to not use these things, Multiselect also is possible on the level of File Explorer file lists and requires a user to know the meaning of modifier keys CTRL and SHIFT in conjunction with files items, Moverbars are even a concept with no similar example in the whole Windows world, so overall and for having an overview of selected items you use a moverbox, which means you have two listboxes for selections (left) and made choices (right). That doesn't require multiselect and moverbars.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top