3.5 X-Function RangeListBox Example

Summary

This example demonstrates how to use ListBox control for Range variable.

Steps

  1. Open X-Function Builder from Tools menu, enter the X-Function name and variables, as in the following picture, and then click Save. Ocguide xfdialog savebutton.png.
    OCguide xf example RangeListBox.png
  2. Open this X-Function in Code Builder to edit the source code. First include the needed header file, as below.
    #include <..\OriginLab\wks_utils.h> // needed for init_GetN_col_list_ctrls function
  3. In the X-Function's main function, collistex, add the following code to get the range string from the specified data range.
    	string str;
    	if(collist)
    		collist.GetRangeString(str, NTYPE_FOR_RANGE);
    	out_str(str);
  4. In the X-Function's before_execute function collistex_before_execute, add the following code to initialize the control of collist variable. It will make collist a ListBox to list column range.
    	bool bIsStart = is_xf_startup(nGetNDialog, dwCntrl);
    	if(bIsStart && (dwCntrl & LTXF_SHOW_DIALOG))
    	{
    		init_GetN_col_list_ctrls(NULL, trGetN.collist);
    	}
  5. Run the X-Function

    1. run collistex -d in the Script window, and then you can see the dialog below.
      Ocguide xfdialog collistex display.png
    2. click the ListBox's triangle button to add columns and you can select/unselect columns in the ListBox.
      Ocguide xfdialog collistex columns.png
    3. click OK. It will output the range of selected columns.