Preselect list view entries

  • Follow


I have a list view control used in a category dialog.  Everything works 
except I cannot seem to preselect items in the list control.  As far as I 
can see I should be able to modify the associated attribute with the items 
like this.

::method initCategories
self~calalog['names'] = .array~of('tab1', ...

::method tab1
self~connectListControl(100, 'test')

::method inittab1
lc = self~getListControl(100, 1)
lc~insertColumn(0,,90)
lc~addRow(,,'item0')
lc~addRow(,,'item1')
lc~addRow(,,'item2')
lc~addRow(,,'item3')
self~test = '1 3'
self~setData
do i = 0 to lc~items
  say 'Item 'i' is 'lc~itemState(i)
end

Which produces output:
Item 0 is
Item 1 is SELECTED
Item 2 is
Item 3 is SELECTED

Which is correct, however when the dialog opens, instead of items 1 & 3 
selected, the first two items 0 & 1 are selected.  No matter which ones I 
attempt to preselect they are always switched to 0 & 1 and if I test the 
item state after the dialog is open it confirms 0 & 1.  So what is changing 
my selection?  If it only selected item 0, I would suspect that I was not 
updating the attribute correctly and was just getting the default.

Stumped.

Phil
---- 


0
Reply Phil 3/4/2008 5:43:37 AM

I don't have time to check this out at the moment, but I have a hunch
that if you move your selection code to the RUN method followed by a
self~run:super it may work.

hth,

Jon
0
Reply Sahananda 3/4/2008 7:22:16 AM


On Mar 3, 9:43=A0pm, "Phil" <obrie...@optusnet.com.au> wrote:
> I have a list view control used in a category dialog. =A0Everything works
> except I cannot seem to preselect items in the list control. =A0As far as =
I
> can see I should be able to modify the associated attribute with the items=

> like this. ...

Phil,

I also didn't have a chance to look at this very closely.  Jon's idea
is a good one, but I would probably take a different approach.

This is what I would do with a dialog, however, I never use the
CategoryDialog and I'm not sure if there is something different about
them.

I would add this to your dialog:

::method InitAutoDetection
   self~NoAutoDetection

and then in InitDialog select the items you want selected.

As far as I'm concerned that's the proper way to do it, because it is
the way you would do it if you were using the Windows API directly.
<grin>

If you can't get it to work, and want to send me your program, I'll
see what it takes to get it to work properly.  I just don't want to
write a program from scratch that uses Category dialogs.

--
Mark Miesfeld
0
Reply Mark 3/5/2008 1:33:56 AM

On Mar 4, 5:33=A0pm, Mark Miesfeld <miesf...@gmail.com> wrote:
> On Mar 3, 9:43=A0pm, "Phil" <obrie...@optusnet.com.au> wrote:
>
> > I have a list view control used in a category dialog. =A0Everything work=
s
> > except I cannot seem to preselect items in the list control. =A0As far a=
s I
> > can see I should be able to modify the associated attribute with the ite=
ms
> > like this. ...
>
> Phil,
>
> I also didn't have a chance to look at this very closely. =A0Jon's idea
> is a good one, but I would probably take a different approach.

Here is some code that works.  Take the oodlist.rex sample file that
comes with ooRexx.  That is a Category dialog with list-view controls.

At the end of the InitDialog method in the sample, change it / add the
following:

  ...
  Item.FirstName =3D "Dave"
  Item.Lastname  =3D "Hewitt"
  Item.Street    =3D "Street 3"
  Item.City      =3D "City 3"
  Item.Age       =3D "49"
  Item.Sex       =3D "M"
  self~UpdateLists(Item.)

  listControl =3D self~GetListControl(101, 1)
  if listContol \=3D=3D .nil then do
    listControl~select(1)
    listControl~select(2)
  end

::method InitAutoDetection
   self~NoAutoDetection


Then in the List method, add the SHOWSELAWAYS flag to the creation of
the list view control:

/* initialize first category page */
::method List
  expose ID_List
  self~AddListControl( ID_List, , 5, 5, 370, 170, "LIST
SHOWSELALWAYS") /* Add a simple list to the first category page */

Now when you run oodlist.rex, it will open up with the bottom two
items selected on the first page of the Category dialog.

Hopefully that is enough to get you going.  If you still have
problems, we will need to see more of your program, more context.  Jon
can surely see what is wrong if he had more code to look at.

--
Mark Miesfeld
0
Reply Mark 3/5/2008 3:17:05 AM

"Mark Miesfeld" <miesfeld@gmail.com> wrote in message 
news:364156c5-a106-40bf-a132-3acafe15070f@u10g2000prn.googlegroups.com...
On Mar 3, 9:43 pm, "Phil" <obrie...@optusnet.com.au> wrote:
> I have a list view control used in a category dialog. Everything works
> except I cannot seem to preselect items in the list control. As far as I
> can see I should be able to modify the associated attribute with the items
> like this. ...


>>I would add this to your dialog:

>>::method InitAutoDetection
>>   self~NoAutoDetection

>>and then in InitDialog select the items you want selected.

Not sure what method I would use to do this step.

>>Mark Miesfeld

Thanks to both you and Jon for your replies.

I tried Jon's suggestion with mixed results but the short is it didn't seem 
to work although I might have not done it correctly but read on :-)

Before I saw Marks idea I realized that I didn't need to go the way I was 
because I was already using a stem to preset other controls in this way:
dlg = .propertySheet~new(dlgData.,,,,)
dlgData.101 = <a string>  /* for a combobox */
dlgData.102 = ...

So added:
dlgData.103 = '1 2 3'  /* for the list view */
But it still failed to set the list view selections correctly but ONLY for 
some particular strings used for the combobox!

For instance if I use: dlgData.103 = "abcdef ghij k" it fails.  If I leave 
off the "k" it works as do other combinations.  I arrived at this string 
after much trial and error with the original names.  It is not dependant on 
the chars used (except numerics don't cause the same problem) but the 6 4 1 
format seems necessary in this example to break it.  I've looked very hard 
for duplicate ids etc.

So neither of my appoaches have worked but I don't expect this will shed any 
light on it so I'll try and get a reproducable snippet from my program to 
post.  Incidently, this is with IBM ObjRexx 312 and I'm unable to test on 
ooRexx 320 until I extract the testcase due to other unsupported 
dependancies.

Phil
----
 


0
Reply Phil 3/5/2008 4:07:50 AM

"Phil" <obrienpw@optusnet.com.au> wrote in message 
news:47ce1c98$0$14479$afc38c87@news.optusnet.com.au...
>
> "Mark Miesfeld" <miesfeld@gmail.com> wrote in message 
> news:364156c5-a106-40bf-a132-3acafe15070f@u10g2000prn.googlegroups.com...
> On Mar 3, 9:43 pm, "Phil" <obrie...@optusnet.com.au> wrote:
>> I have a list view control used in a category dialog. Everything works
>> except I cannot seem to preselect items in the list control.

>> I'll try and get a reproducable snippet from my program to post.

I have a reproducable failure.

/* test.rc */
#define test   100
#define LC      101
#define checkbox 102

test DIALOG 90, 20, 159, 95
STYLE DS_MODALFRAME | WS_POPUP | WS_DLGFRAME | WS_SYSMENU
FONT 8, "arial"
{
 CHECKBOX "Checkbox", checkbox, 16, 17, 49, 12, BS_AUTOCHECKBOX | WS_TABSTOP
 CONTROL "ListView", LC, "SysListView32", LVS_LIST | LVS_SHOWSELALWAYS | 
LVS_SORTASCENDING | LVS_NOLABELWRAP | LVS_ALIGNLEFT | LVS_NOCOLUMNHEADER | 
LVS_NOSORTHEADER | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 13, 38, 
126, 49
}

 /* test */
  test = .test~new(init.,,,,)

  init.101 = 1                           -- list view select
  init.102 = 'abcdefghijklmnqr'  -- checkbox

  test~createCenter(150, 150,,'SYSTEMMODAL',,'arial',8)
  test~execute

::requires "OODIALOG.CLS"
::requires "OODWIN32.CLS"

::class test subclass propertySheet

::method InitCategories
  self~catalog['names'] = .array~of('Tab 1')
  self~catalog['page']['font'] = 'arial'
  self~catalog['page']['fsize'] = 8
  self~catalog['page']['btnwidth'] = 50

::method tab1
  self~loaditems('test.rc', 100)

::method initTab1
  rlc = self~getListControl('LC',1)
  rlc~insertColumn(0,,90)
  rlc~addrow(,,'TEST ITEM 0')
  rlc~addrow(,,'TEST ITEM 1')
  rlc~addrow(,,'TEST ITEM 2')

Clearly the value attempted to be used for the checkbox is invalid but as 
shown the program works without error, correctly preselecting the second 
item.  If you add one more character to the checkbox attribute string it 
will also preselect the first item without complaint.  So it looks like 
something overflows and gets written on someone else's space.  I reckon this 
should either not fail or toss up an error - would have saved me a day's 
work :-)

I've used the PropertySheet and also the resource because that's what I was 
using.  I would guess it fails for single dialogs as well.
It fails on both ooRexx 320 and IBM Object Rexx 312 as I assume these still 
share the same code in this area.

Mark, thanks very much for the additional help with the alternative method 
which looks like it will suit me better in any case.

Phil
---



0
Reply Phil 3/6/2008 2:47:21 AM

On Mar 5, 6:47=A0pm, "Phil" <obrie...@optusnet.com.au> wrote:
> "Phil" <obrie...@optusnet.com.au> wrote in message
>
> news:47ce1c98$0$14479$afc38c87@news.optusnet.com.au...
>
>
>
> > "Mark Miesfeld" <miesf...@gmail.com> wrote in message
> >news:364156c5-a106-40bf-a132-3acafe15070f@u10g2000prn.googlegroups.com...=

> > On Mar 3, 9:43 pm, "Phil" <obrie...@optusnet.com.au> wrote:
> >> I have a list view control used in a category dialog. Everything works
> >> except I cannot seem to preselect items in the list control.
> >> I'll try and get a reproducable snippet from my program to post.
>
> I have a reproducable failure.

Phil,

Your program seems to work as I would expect it to, at least on
ooRexx.  I don't have IBM's Object Rexx currently installed anywhere
to take a look at it.

Here is a little info.  Change your init of the stem to this:

  init.101 =3D "1 2"                           -- list view select
  --init.102 =3D 'abcdefghijklmnqrs'  -- checkbox
  init.102 =3D '1'  -- checkbox

You have 3 items in the list view.  Items in a list view use a 0-based
index, so the above selects the bottom 2 items in the list view and
has the check box checked.

The values you use to check a check box or a radio button are 0 or 1.
The underlying C code that ooDialog is written in uses atol() to
convert a string to a number.  The values sent to the C functions are
always strings.  So a 1 or 19 or a 234233 in Rexx is sent as the ascii
string to the C function

atol() returns 0 if it can not convert the string to a number.  So,
'cat' or 'dog' or 'abcdefghijklmnqrs' all get converted to a 0.

The original IBM ooDialog code does very little error checking,
presumably because it was first designed to run Windows 3.1 and
machines back then did not have much horse power.  It may be that
sending too long of a string to atol() causes an overflow.  At least
in my test with ooRexx, I didn't see any problems.

Anyhow, the bottom line is that using a stem to initialize your dialog
controls seems to work correctly in Category dialogs.

As another point of information, I'll offer this.  There are two
techniques to initializing the controls in your dialog.

1.) You can use a stem to initialize them as you do here.  And then at
the end of the dialog execution, the stem contains the values of the
controls.

2.) You can turn off autodetection.  In the InitDialog method, set the
state of all your controls to what you want.  When the dialog ends,
you gather what information you need to preserve from the state of the
controls and send it back, somehow.  There are probably a zillion
different ways to do that.  For instance, you could put all the
information in a table and add a method to your ooDialog class called
say, getResults.  When the dialog ends you invoke getResults, get the
table and do what you want with it.

I *always* use method number 2.

Method number 1 is probably less work in many cases, but you also have
less control.  As I recall, method number 1 is what the IBM developers
expected people to use, but it is not documented well.  It seems to
cause a lot of confusion.  I never really understood it, until I got
access to the source code.  By that time, I had already decided to
always use method number 2, becuase it always worked as I expected.

You can not really mix the 2 methods.

--
Mark Miesfeld
0
Reply Mark 3/6/2008 3:44:14 PM

On Mar 6, 7:44=A0am, Mark Miesfeld <miesf...@gmail.com> wrote:
> On Mar 5, 6:47=A0pm, "Phil" <obrie...@optusnet.com.au> wrote:
>
> > "Phil" <obrie...@optusnet.com.au> wrote in message
>
> >news:47ce1c98$0$14479$afc38c87@news.optusnet.com.au...
>
> > > "Mark Miesfeld" <miesf...@gmail.com> wrote in message
> > >news:364156c5-a106-40bf-a132-3acafe15070f@u10g2000prn.googlegroups.com.=
...
> > > On Mar 3, 9:43 pm, "Phil" <obrie...@optusnet.com.au> wrote:
> > >> I have a list view control used in a category dialog. Everything work=
s
> > >> except I cannot seem to preselect items in the list control.
> > >> I'll try and get a reproducable snippet from my program to post.

Phil,

Here is the test program you posted, reworked to initialize the
controls and collect the state after execution without using a stem.
(It uses the same .rc file as you originally posted.)  It sets the
check box to checked and selects 3 items in the list-view control.

/* test */

  test =3D .test~new
  test~createCenter(150, 150,,'SYSTEMMODAL',,'arial',8)
  test~execute

  dTable =3D test~getResults

  if dTable~items =3D=3D 0 then do
    say 'The user canceled'
    return -1
  end

  if dTable['check'] then say 'The check box was checked'
  else say 'The check box was not checked'

  count =3D dTable['listCount']
  say 'There were' count 'item(s) selected'
  if count > 0 then say 'The item numbers selected were:'
dTable['selectedItems']
  return 0

::requires "OODWIN32.CLS"

::class test subclass propertySheet

::method InitAutoDetection
   self~NoAutoDetection

::method InitCategories
  self~catalog['names'] =3D .array~of('Tab 1')
  self~catalog['page']['font'] =3D 'arial'
  self~catalog['page']['fsize'] =3D 8
  self~catalog['page']['btnwidth'] =3D 50

::method tab1
  expose dataTable
  self~loaditems('test.rc', 100)

::method initTab1
  expose rlc checkBox dataTable

  rlc =3D self~getListControl('LC',1)
  rlc~insertColumn(0,,90)
  rlc~addrow(,,'TEST ITEM 0')
  rlc~addrow(,,'TEST ITEM 1')
  rlc~addrow(,,'TEST ITEM 2')
  rlc~addrow(,,'TEST ITEM 3')
  rlc~addrow(,,'TEST ITEM 4')
  rlc~addrow(,,'TEST ITEM 5')
  rlc~addrow(,,'TEST ITEM 6')
  rlc~addrow(,,'TEST ITEM 7')
  rlc~addrow(,,'TEST ITEM 8')
  rlc~addrow(,,'TEST ITEM 9')

  rlc~~select(1)~~select(3)~~select(5)

  checkBox =3D self~getCheckControl('checkbox', 1)
  checkBox~check

  /* If the user cancels, the data table will be empty */
  dataTable =3D .table~new

::method ok
  expose dataTable checkBox rlc

  dataTable['check'] =3D (checkBox~isChecked =3D=3D 'CHECKED')

  count =3D rlc~selectedItems
  dataTable['listCount'] =3D count
  if count > 0 then do
    items =3D ""
    index =3D rlc~selected
    do i =3D 2 to count
      items =3D items index
      index =3D rlc~nextSelected(index)
    end
    items =3D items index
    dataTable['selectedItems'] =3D items
  end

  self~ok:super

::method getResults
  expose dataTable
  return dataTable

0
Reply Mark 3/6/2008 4:27:59 PM

"Mark Miesfeld" <miesfeld@gmail.com> wrote in message 
news:bd9b1511-86d5-475d-8221-0a61afb2870e@s12g2000prg.googlegroups.com...
On Mar 5, 6:47 pm, "Phil" <obrie...@optusnet.com.au> wrote:
> "Phil" <obrie...@optusnet.com.au> wrote in message
>
> news:47ce1c98$0$14479$afc38c87@news.optusnet.com.au...
>
>
>
> > "Mark Miesfeld" <miesf...@gmail.com> wrote in message
> >news:364156c5-a106-40bf-a132-3acafe15070f@u10g2000prn.googlegroups.com...
> > On Mar 3, 9:43 pm, "Phil" <obrie...@optusnet.com.au> wrote:
> >> I have a list view control used in a category dialog. Everything works
> >> except I cannot seem to preselect items in the list control.
> >> I'll try and get a reproducable snippet from my program to post.
>
> I have a reproducable failure.

>>Phil,

>>Your program seems to work as I would expect it to, at least on
>>ooRexx.  I don't have IBM's Object Rexx currently installed anywhere
>>to take a look at it.

This is really strange then because I tested this on ooRexx 320 which is 
installed on different hardware from IBM's rexx and it definitely failed.

>>Here is a little info.  Change your init of the stem to this:
  >>init.101 = "1 2"                           -- list view select
  >>--init.102 = 'abcdefghijklmnqrs'  -- checkbox
  >>init.102 = '1'  -- checkbox

As I said, I was aware that this was invalid for a checkbox but it did 
highlight the problem I was having which if you recall originally showed 
itself when I used a particular string to select from a combobox - and the 
string was in this case quite valid.  There is definitely something going on 
there.

>>Anyhow, the bottom line is that using a stem to initialize your dialog
>>controls seems to work correctly in Category dialogs.

Can't see why it didn't fail for you... adding the 's' caused it to select 
item zero for me.

>>As another point of information, I'll offer this.  There are two
>>techniques to initializing the controls in your dialog.

>>1.) You can use a stem to initialize them as you do here.  And then at
>>the end of the dialog execution, the stem contains the values of the
>>controls.

This is the method I've always used because the alternative is not really 
documented or is well hidden.

>>2.) You can turn off autodetection.  In the InitDialog method, set the
>>state of all your controls to what you want.  When the dialog ends,
>>you gather what information you need to preserve from the state of the
>>controls and send it back, somehow.  There are probably a zillion
>>different ways to do that.  For instance, you could put all the
>>information in a table and add a method to your ooDialog class called
>>say, getResults.  When the dialog ends you invoke getResults, get the
>>table and do what you want with it.

>>I *always* use method number 2.

I will be able to say this from now on!
I have changed my program to use this method and it not only works perfectly 
it is considerably more elegant and understandable because all the methods 
needed to both gather and select the data can be all together instead of 
before where the initial gather was in the method that creates the class (so 
it had the data in advance) of execute.  The property sheet dialog is opened 
from a parent dialog so these two lumps of code are in different files.

>>Method number 1 is probably less work in many cases, but you also have
>>less control.  As I recall, method number 1 is what the IBM developers
>>expected people to use, but it is not documented well.  It seems to
>>cause a lot of confusion.  I never really understood it, until I got
>>access to the source code.  By that time, I had already decided to
>>always use method number 2, becuase it always worked as I expected.

Never had a problem until now but in my experience it was clunky to use.

>>You can not really mix the 2 methods.

Yes, it seems that method 2 disables method 1 which is of no consequence.

>>--
>>Mark Miesfeld

Thanks, once again Mark for the guidance.

Phil
---- 


0
Reply Phil 3/7/2008 12:11:56 AM

8 Replies
235 Views

(page loaded in 0.384 seconds)

Similiar Articles:






7/28/2012 1:57:25 PM


Reply: