New topic: 

Selected ListBox Cells to Textfields?

<http://forums.realsoftware.com/viewtopic.php?t=47220>

         Page 1 of 1
   [ 9 posts ]                 Previous topic | Next topic          Author  
Message        RicSum          Post subject: Selected ListBox Cells to 
Textfields?Posted: Fri Mar 08, 2013 6:14 pm                         
Joined: Fri Jun 05, 2009 4:54 pm
Posts: 448
Location: London, England                Hi,
I have a window called "Stats1" which contains a ListBox called "List" with 2 
columns.
When a user right-clicks on a row in the ListBox and selects edit, I have an 
edit window display 2 TextFields ("TextField1" and "TextField2").

Could someone kindly show me how I autofill TextField1 with the first cell, and 
TextField2 with the second cell.

I have been trying this all day and am now so frustrated, that I need help.

Here is what I have so far:

 for i As Integer= Stats1.List.ListCount - 1 DownTo 0
  if Stats1.List.List(i).Selected(Row)=true then
  TextField1.text=""
  TextField2.text=""
  end if
next


Thank you all in advance.      
_________________
RealStudio Professional Edition 2012 r2
Developing on OS X  10.8 (Mountain Lion)
Deploying on Windows XP / 7 / 8  
                             Top                timhare          Post subject: 
Re: Selected ListBox Cells to Textfields?Posted: Fri Mar 08, 2013 6:51 pm       
                  
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12125
Location: Portland, OR  USA                First, your code:
for i = 0 to ...
if ...Selected(row)...

You're not using the loop variable in your if/then test.  But why not use 
ListIndex instead of looping through the listbox?

Second, a better approach:
Give the window a constructor that takes 2 strings as parameters.  Store the 
strings in properties of the window.  Then in the respective textfield's Open 
event, load the Text from the appropriate property. When the text changes, 
store it back into the window property.

Make the window modal and give it an OK and Cancel button.  After the window 
closes, if the OK button was pressed, pull the strings from the appropriate 
properties and load them back into the listbox.   
                             Top                RicSum          Post subject: 
Re: Selected ListBox Cells to Textfields?Posted: Fri Mar 08, 2013 6:56 pm       
                  
Joined: Fri Jun 05, 2009 4:54 pm
Posts: 448
Location: London, England                ?????????
Thank you so much for trying to help, but I did not understand 1 word - that 
was wayyyyy beyond my comprehension 

Thanks anyway.      
_________________
RealStudio Professional Edition 2012 r2
Developing on OS X  10.8 (Mountain Lion)
Deploying on Windows XP / 7 / 8  
                             Top                timhare          Post subject: 
Re: Selected ListBox Cells to Textfields?Posted: Fri Mar 08, 2013 6:59 pm       
                  
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12125
Location: Portland, OR  USA                OK, so try this.
i = Stats1.List.ListIndex
if i>= 0 then
  TextField1.Text = Stats1.List.Cell(i,0)
  TextField1.Text = Stats1.List.Cell(i,1)
end
   
                             Top                RicSum          Post subject: 
Re: Selected ListBox Cells to Textfields?Posted: Fri Mar 08, 2013 7:05 pm       
                  
Joined: Fri Jun 05, 2009 4:54 pm
Posts: 448
Location: London, England                That code threw an error - i does not 
exist.
So I added:
Dim i as string

but that also threw an error: - expect Integer 32 but got string.

So I changed it to:
Dim i as Integer 32

that also threw an error - syntax error

aaaaaaaarrrrrrrrrrrrrrggggggggggggghhhhhhhhhhhhhhhh     
_________________
RealStudio Professional Edition 2012 r2
Developing on OS X  10.8 (Mountain Lion)
Deploying on Windows XP / 7 / 8  
                             Top                RicSum          Post subject: 
Re: Selected ListBox Cells to Textfields?Posted: Fri Mar 08, 2013 7:09 pm       
                  
Joined: Fri Jun 05, 2009 4:54 pm
Posts: 448
Location: London, England                SUCCESS

I changed it to Dim i as Integer

THANK YOU SO MUCH TIM !      
_________________
RealStudio Professional Edition 2012 r2
Developing on OS X  10.8 (Mountain Lion)
Deploying on Windows XP / 7 / 8  
                             Top                RicSum          Post subject: 
Re: Selected ListBox Cells to Textfields?Posted: Fri Mar 08, 2013 7:43 pm       
                  
Joined: Fri Jun 05, 2009 4:54 pm
Posts: 448
Location: London, England                Ok,
One final problem I am having with the code below - I need help to replace 
lines 4 and 5, so that the selected ListBox row is REPLACED, as opposed to 
removed and then the new row added to the bottom of the ListBox??


Dim i as integer
i = Stats1.List.ListIndex
if i>= 0 then
  Stats1.List.RemoveRow(i)
  Stats1.List.AddRow(TextField1.Text,TextField2.Text)
  Stats1.MakeChart
  StatEdit.close
else
  beep
  msgbox "Please ensure both fields are completed !"
end if


Thanks      
_________________
RealStudio Professional Edition 2012 r2
Developing on OS X  10.8 (Mountain Lion)
Deploying on Windows XP / 7 / 8  
                             Top                timhare          Post subject: 
Re: Selected ListBox Cells to Textfields?Posted: Fri Mar 08, 2013 7:53 pm       
                  
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12125
Location: Portland, OR  USA                Do the reverse of the original code:
if i >= 0 then
  Stats1.List.Cell(i,0) = Textfield1.Text
  Stats1.List.Cell(i,1) = Textfield2.Text
end
   
                             Top                RicSum          Post subject: 
Re: Selected ListBox Cells to Textfields?Posted: Fri Mar 08, 2013 8:00 pm       
                  
Joined: Fri Jun 05, 2009 4:54 pm
Posts: 448
Location: London, England                Your'e a STAR !

I am so grateful there are people such as yourself, who are prepared to be 
patient and help others.

Thank you Tim !      
_________________
RealStudio Professional Edition 2012 r2
Developing on OS X  10.8 (Mountain Lion)
Deploying on Windows XP / 7 / 8  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 9 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to