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

GridView Sticky Discussion
Goto page Previous  1, 2, 3, 4, 5
 
Post new topic   Reply to topic    KiXforms Forum Index -> Discussion
View previous topic :: View next topic  
Author Message
benny69
KiXforms Advocate
KiXforms Advocate


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

PostPosted: Mon Jan 24, 2005 6:11 pm    Post subject: Reply with quote

Here is a functional example:
Code:

;region Setup Variables
$Domain = @Domain
$Version = "Build(1.0.0.1)"
$SystemDir = %SystemROOT%
$InstallDirectory = "$SystemDir\System32"
$TempDir = %ASESCRIPTPATH%
$objRootDSE = GetObject("LDAP://rootDSE")
If Not $objRootDSE = ""
   $defaultNamingContext = $objRootDSE.Get("defaultNamingContext")
EndIf
$System = CreateObject("Kixtart.System")
$fontsize = 8.25
;endregion

;region Main Form
Break On

$Form = $System.Form()
$Form.Size = 650,480
$Form.Font = $System.Font("Verdana",$fontsize)
$Form.Text = "GridView " + $VERSION
$Form.Icon = 61

;region MENUs
$Menu = $System.MainMenu()
$Menu.Style = 0
$Menu.ImageLiSt = $System.BuiltinImageLiSt()

$FileMenu = $Menu.MenuItems.Add("File")
$ExitMenu = $FileMenu.MenuItems.Add("Exit")
$ExitMenu.ImageIndex = 60
$ExitMenu.Shortcut = "Alt+F4"
$ExitMenu.ShortcutText = "Alt+F4"
$ExitMenu.OnClick = "OnExit()"

$EditMenu = $Menu.MenuItems.Add("Edit")

$ToolsMenu = $Menu.MenuItems.Add("Tools")
$GMSMenu = $ToolsMenu.MenuItems.Add("Get Manageable Services")
$GMSMenu.ImageIndex = 56
$GMSMenu.Shortcut = "Ctrl+F1"
$GMSMenu.OnClick = "GridviewUpdate()"

$Form.Menu = $Menu
;endregion

;region Status Bar
$StatusBar = $Form.StatusBar()
$StatusBar.Dock = "Bottom"
$StatusBar.DockPadding = 4,2,2,2

$ProgressBar = $StatusBar.Controls.Progressbar()
$ProgressBar.Maximum = 100
$ProgressBar.Minimum = 0
$ProgressBar.Style = 1
$ProgressBar.Step = 10
$ProgressBar.Dock = "Right"
$ProgressBar.Width = 100
$ProgressBar.Left = $form.Width - $ProgressBar.Width - 25

$StatBarInfo = $StatusBar.Controls.Label()
$StatBarInfo.BorderStyle = 2
$StatBarInfo.TextAlign = "MiddleLeft"
$StatBarInfo.Dock = "Fill"
;endregion

;region Form Controls
$MainSplit = $Form.SplitContainer()
$MainSplit.Dock = "Fill"
$MainSplit.SplitterDistance = 0.20 * $MainSplit.ClientWidth
$MainSplit.Panel1Collapsed = 1

$TreeView = $MainSplit.Panel1.TreeView()
$TreeView.Dock = "Fill"
$TreeView.OnDoubleClick = "TreeViewDoubleClick()"
$TreeView.ImageList = $System.BuiltinImageList

$TablesNode = $TreeView.Nodes.Add("Tables")
$TablesNode.ImageIndex = 45
$TablesNode.SelectedImageIndex = 46

$ViewsNode = $TreeView.Nodes.Add("Views")
$ViewsNode.ImageIndex = 45
$ViewsNode.SelectedImageIndex = 46

$GridView = $MainSplit.Panel2.GridView()
$GridView.Dock = "Fill"

$ErrorBox = $System.MessageBox()
$ErrorBox.Title = $TITLE
$ErrorBox.Icon = $System.MessageBoxIcon.Error
;endregion

$GridView.Focus()

$Form.Center
$Form.Show
GridviewUpdate()

While $Form.Visible
 $= Execute($Form.DoEvents())
Loop
Exit 1
;endregion

;region Form Functions

Function AdvanceProgressBar($Step,Optional $Text)
   $Count = $Count + $Step
   If $Count > 100
      $Count = 0
   EndIf
   $StatBarInfo.Text = $Text
   $ProgressBar.Value = $Count
   
   Sleep 0.05
EndFunction

Function ClearGrid()
   $GridView.BeginUpdate
   $GridView.RowCount = 0
   $GridView.ColumnCount = 3
   $GridView.Columns(0).Width = 150
   $GridView.Columns(1).Width = 150
   $GridView.Columns(2).Width = 100
   $GridView.Columns(0).HeaderText = "Display Name"
   $GridView.Columns(1).HeaderText = "Service Name"
   $GridView.Columns(2).HeaderText = "Status"
   $GridView.EndUpdate
EndFunction

Function GridviewUpdate() ;$RowCount
   Dim $row
   
   ClearGrid()
   
   $MainSplit.Panel1Collapsed = 1
   
   $GridView.BeginUpdate
   $GridView.RowCount = 0
   $GridView.ColumnCount = 0
   $GridView.ColumnCount = 3
   $GridView.Columns(0).HeaderText = "Display Name"
   $GridView.Columns(1).HeaderText = "Service Name"
   $GridView.Columns(2).HeaderText = "Status"
   $GridView.Columns(2).CellType = "Combobox"
   $GridView.OnCellValueChanged = "CheckCombobox()"
   
   $StatusListItems = $System.ListItemCollection()
   $= $StatusListItems.Add("Started")
   $= $StatusListItems.Add("Stoped")
   $GridView.Columns(2).Items = $StatusListItems

   $x = 0
   $objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + @WKSTA + "\root\cimv2")
   $colServices = $objWMIService.ExecQuery ("Select * from Win32_Service")
   For Each $objService in $colServices
      $Row = $GridView.Rows.Add()
      AdvanceProgressBar(1,"Adding " + $objService.DisplayName)
      $GridView.Cells($x,0).Text = $objService.DisplayName
      $GridView.Cells($x,1).Text = $objService.Name
      If $objService.Started = -1
         $GridView.Cells($x,2).Value = "Started"
         $GridView.Cells($x,2).ForeColor = "Green"
      Else
         If $objService.Started = 0
            $GridView.Cells($x,2).Value = "Stoped"
            $GridView.Cells($x,2).ForeColor = "Red"
         EndIf
      EndIf
      $x = $x + 1
   Next
   ;$GridView.Sort(0,"ascending")
   $GridView.Sort(0,0)
   $GridView.Columns(0).Width = -1
   $GridView.Columns(1).Width = -1
   
   $GridView.CurrentRowIndex = 0
   $GridView.CurrentColumnIndex = 0
   $GridView.EndUpdate
   $Count = 0
   AdvanceProgressBar(0,"")
   $Form.width = $GridView.Columns(0).Width + $GridView.Columns(1).Width + $GridView.Columns(2).Width + 30
EndFunction

Function CheckCombobox()
;  * Location Options *
;   CurrentRow
;   CurrentRowIndex
;   CurrentColumn
;   CurrentColumnIndex
;   CurrentCell
   $GridView.Enabled = "false"
   $Index = $GridView.CurrentRowIndex
   $ServiceName = $GridView.Cells($Index,1).Value
   $Status = $GridView.Cells($Index,2).Value
   If $Status = "Started"
      StartServerService($ServiceName)
   Else
      If $Status = "Stoped"
         StopServerService($ServiceName)
      EndIf
   EndIf
   GridviewUpdate()
   $GridView.Enabled = "true"

EndFunction

Function StopServerService($Service)
   $objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + @WKSTA + "\root\cimv2")
   $colServiceList = $objWMIService.ExecQuery("Associators of {Win32_Service.Name='$Service'} Where AssocClass=Win32_DependentService Role=Antecedent" )

   For Each $objService in $colServiceList
      $errReturn = $objService.StopService()
   Next

   Sleep 3

   $colServiceList = $objWMIService.ExecQuery ("Select * from Win32_Service where Name='$Service'")

   For Each $objService in $colServiceList
      $errReturn = $objService.StopService()
   Next
EndFunction

Function StartServerService($Service)
   $objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + @WKSTA + "\root\cimv2")
   $colServiceList = $objWMIService.ExecQuery ("Select * from Win32_Service Where Name='$Service'")
   
   For Each $objService in $colServiceList
      $errReturn = $objService.StartService()
   Next
   
   Sleep 3
   
   $colServiceList = $objWMIService.ExecQuery("Associators of {Win32_Service.Name='$Service'} Where AssocClass=Win32_DependentService Role=Dependent" )
   
   For Each $objService in $colServiceList
      $errReturn = $objService.StartService()
   Next
EndFunction

;endregion


Note: that the cell location options that I am aware of are as follows:

* Location Options *
$GridView.CurrentRow
$GridView.CurrentRowIndex
$GridView.CurrentColumn
$GridView.CurrentColumnIndex
$GridView.CurrentCell

In this example I use $GridView.CurrentRowIndex
I hope this will help.

_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)


Last edited by benny69 on Mon Jun 06, 2005 1:29 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Jochen
KiXforms Devotee
KiXforms Devotee


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Tue Jan 25, 2005 9:40 am    Post subject: Reply with quote

nah,

9it doesn't help because I haven't got any LDAP round here to run against.
īThank you for the effort, didn't need a sample, but thanks anyways Very Happy

_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Discussion All times are GMT
Goto page Previous  1, 2, 3, 4, 5
Page 5 of 5

 
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