WireLess Studio Widgets Developer's Guide
WSWDG ContentsWStWidget class reference

GetSelectedItem

This methods retrieves the currently selected item on a WS_LIST_CTRL (An item is a row) or a WS_MENU (An item is an option) widget.

Ole declaration

SHORT GetSelectedItemByName(LPCTSTR sObjectName);

SHORT GetSelectedItemById(SHORT usObjectId);

Parameters
sObjectName
The name of the target widget.
usObjectId
The id of the target widget.
Return Value

On success, GetSelectedItem returns the zero based index of  the selected item on a widget. If there's no items selected, GetSelectedItem returns -1. On error GetSelectedItem returns 32767. To get extended information, call WStError::GetLastErrorCode.

Remarks
Example
C#
using WirelessStudioOleWidgets;
WStWidget oWidget = new WStWidget();
short sListCtrlId= 4;
oFactory.CreateWidgetById((short)WSTFactoryConstants.WS_LIST_CTRL, sListCtrlId, "", 0,0, 50, 50, "");
oWidget.AddColumById(sListCtrlId, 40, "Product Id");
oWidget.AddRowById(sListCtrlId, 0);
oWidget.AddRowById(sListCtrlId, 0);
oWidget.AddRowById(sListCtrlId, 0);

if(oWidget.GetSelectedItemById(sListCtrlId) != -1)
{
	oWidget.SetRowTextById(sListCtrlId, oWidget.GetSelectedItemById(sListCtrlId), 0, "44423");
}

Visual Basic 6 (Full Example: ListCtrlDemoModule.bas.txt)
Public wsWidget As New WStWidget
...
 Case "newRowTextField"
	sEventValue = wsForm.GetLastEventStrValue()
	'Changes the text of the first column of a previously selected row
	If wsWidget.GetSelectedItemByName("myListCtrl") <> -1 Then
		wsWidget.SetRowTextByName "myListCtrl", wsWidget.GetSelectedItemByName("myListCtrl"), _
			0, sEventValue
	End If
...
See also

AddColumn | ClearColumns | SetRowText | SetRowIcon | AddRow | ClearRows | ReadRowsFromFile | SetLoadMode | GetOption | ChangeMenuType | ClearOptions

WStWiget class reference | WStForm class reference | WStFactory class reference | WStError class reference