KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

ListBox - remove multiple items in multiExtended mode

 
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion
View previous topic :: View next topic  
Author Message
marticus24
KiXforms Novice
KiXforms Novice


Joined: 17 Jun 2008
Posts: 2

PostPosted: Tue Jun 17, 2008 7:25 pm    Post subject: ListBox - remove multiple items in multiExtended mode Reply with quote

HI all! I'm new to the forums, but definitely not new to Kix. I've been using it for my administrative scripting for over 4 years now, and love it. I'm a bit new to kix.net, but am not new to kixforms in general, so sorry if this seems like newbie-type question.

I'm working on creating a tool for our helpdesk to use to provision users in AD. On my groups tab, I'm showing two listboxes, one on the left, listing all groups in AD and one on the right with the groups that the new user will be added to. I'm having no issue populating the lefthand listbox with existing AD groups, but am having issues with removing the selected items from the available groups box after they've been added to the right-side box.

I've seen a couple of examples by benny69 i believe, that show how to do this in simple selection mode, but need to know if there is an easy way to do so in multExtended mode as I'd like to allow them to select multiple groups at a time and just hit the > button once. Here is the code snippet that kind of works:

Code:


$arrSelectedItems = $listBoxAvailableGroups.SelectedItems
   For Each $group in $arrSelectedItems
      
      $=$listBoxAddToGroups.Items.Add($group)   
      $=$listBoxAvailableGroups.Items.Remove($group)
      $arrSelectedItems = $listBoxAvailableGroups.SelectedItems
   Next


Now, this works, but only performs one iteration of the loop upon each button press. I've tried some other variations of this, to no avail. I'm wondering if I need to somehow update the list of selected items, which is what I tried to do with the last line in the loop, but still doesn't seem to get me past one iteration per click.

Any input is greatly appreciated!

PS - I'm glad this forum exists, there is a wealth of useful info to be shared here.
Back to top
View user's profile Send private message
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Wed Jun 18, 2008 1:26 pm    Post subject: Reply with quote

Hi marticus24, and Welcome to the world of KiXforms.Net

I think this might be what you are looking for:
Code:

Break On
$System = CreateObject("Kixforms.System")
If Not $System
   $nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
   Quit()
EndIf

$Form1 = $System.Form()
$Form1.StartPosition = 1  ;FormStartPosition_CenterScreen
$Form1.Size = $System.Size(338,224) ;(Width,Height)
$Form1.Text = "ListBox Example"

$ListBox1 = $System.ListBox()
$ListBox1.DoubleClick = "AddToListBox2()"
$ListBox1.Height = 173
$ListBox1.Left = 10
$ListBox1.SelectionMode = 3  ;MultiExtended
$ListBox1.Top = 10
$nul = $Form1.Controls.Add($ListBox1)

For $Index = 1 to 6
  $Item = $ListBox1.Items.Add("Line"+$Index)
Next

$Button1 = $System.Button()
$Button1.Click = "AddAllToListBox2()"
$Button1.Height = 30
$Button1.Left = 150
$Button1.Text = ">>"
$Button1.Top = 30
$Button1.Width = 30
$nul = $Form1.Controls.Add($Button1)

$Button2 = $System.Button()
$Button2.Click = "AddToListBox2()"
$Button2.Height = 30
$Button2.Left = 150
$Button2.Text = ">"
$Button2.Top = 70
$Button2.Width = 30
$nul = $Form1.Controls.Add($Button2)

$Button3 = $System.Button()
$Button3.Click = "RemoveFromListBox2()"
$Button3.Height = 30
$Button3.Left = 150
$Button3.Text = "<"
$Button3.Top = 110
$Button3.Width = 30
$nul = $Form1.Controls.Add($Button3)

$Button4 = $System.Button()
$Button4.Click = "RemoveAllFromListBox2()"
$Button4.Height = 30
$Button4.Left = 150
$Button4.Text = "<<"
$Button4.Top = 150
$Button4.Width = 30
$nul = $Form1.Controls.Add($Button4)

$ListBox2 = $System.ListBox()
$ListBox2.DoubleClick = "RemoveFromListBox2()"
$ListBox2.Height = 173
$ListBox2.Left = 200
$ListBox2.SelectionMode = 3  ;MultiExtended
$ListBox2.Top = 10
$nul = $Form1.Controls.Add($ListBox2)

$Form1.Show  ;Displays the Form

While $Form1.Visible
   $Nul = Execute($Form1.DoEvents())
Loop
Exit 0

Function AddAllToListBox2()

   $ListBox2.Items.Clear
   For $x = 0 to $ListBox1.Items.Count
      If $ListBox1.Items.Item($x) <> ""
         $Item = $ListBox2.Items.Add($ListBox1.Items.Item($x))
      EndIf
   Next
   
EndFunction

Function AddToListBox2()
   
  For $Index = 0 to $ListBox1.SelectedItems.Count
    $ListItem = "No"
    For $x = 0 to $ListBox2.Items.Count
      If $ListBox2.Items.Item($x) = $ListBox1.SelectedItems.Item($Index)
        $ListItem = "Yes"
      EndIf
    Next
    If $ListItem = "No"
      $Item = $ListBox2.Items.Add($ListBox1.SelectedItems.Item($Index))
    EndIf
  Next
 
  For $Index = 0 to $ListBox1.Items.Count
    $ListBox1.SetSelected($Index,0)
  Next
 
EndFunction

Function RemoveFromListBox2()
 
  For $Index = 0 to $ListBox2.SelectedItems.Count
    $ListBox2.Items.Remove($ListBox2.SelectedItem)
  Next
 
EndFunction

Function RemoveAllFromListBox2()

   $ListBox2.Items.Clear

EndFunction

_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
marticus24
KiXforms Novice
KiXforms Novice


Joined: 17 Jun 2008
Posts: 2

PostPosted: Wed Jun 18, 2008 1:35 pm    Post subject: Reply with quote

Thanks for the reply... that code does work, but not quite how I'd wanted it to. Right before you posted, I discovered how to make mine work:

Code:
Function rightArrowClick()   
   $arrSelectedItems = $listBoxAvailableGroups.SelectedItems
   For Each $group in $arrSelectedItems
      $=$listBoxAddToGroups.Items.Add($group)   
      $=$listBoxAvailableGroups.Items.Remove($group)
      $arrSelectedItems = $listBoxAvailableGroups.SelectedItems
      rightArrowClick()
   Next
EndFunction


Only difference from what I posted before was a recursive function call to the function doing the work. This works like a charm... now just to decide which code to use.

Thanks for the input. Also, if you see any potential problem with using what I have posted, please let me know.

Thanks again!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group