#203431 - 2011-11-01 11:05 PM
Re: dynamically creating textboxes
[Re: Dr_Rick]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
Here is my attempt at the scenario...Let me know if I'm off base. But it creates the form,listview and the subsequent edit form based off of the $COLUMNS variable I created at the beginning for testing.
Break On
$RC=setoption("NoVarsinstrings","on")
$RC=setoption("NoMacrosinstrings","on")
$COLUMNS = 8
$System = CreateObject("Kixtart.System")
$Form = $System.Form()
$Form.width = 100*$columns
$Form.Height = 400
$Form.Center()
$Listview = $Form.Controls.Add("ListView")
$Listview.Width = $Form.Width-100
$Listview.Height = 300
$Listview.Center()
$Listview.Top = 10
PopulateListview()
$EditButton = $Form.Controls.Add("ToolButton")
$EditButton.Text = "Edit"
$EditButton.Center()
$EditButton.Top = $ListView.Bottom + 15
$EditButton.OnClick = "EditListViewItem()"
$Form.Show()
$Form.SetFocus()
While $Form.Visible
$Nul = Execute($System.DoEvents)
Loop
Exit 0
Function EditListViewItem()
If $ListView.SelectedItems.Count < 1
Exit 0
Endif
$EditForm = $System.Form()
$EditForm.Width = 110*$ListView.Columns.Count
$EditForm.Height = 140
$EditForm.Center()
ReDim $aSelected[$ListView.Columns.Count - 1]
For Each $Item In $ListView.SelectedItems
For $x = 0 to $ListView.Columns.Count - 1
$aSelected[$x] = $Item.SubItems($x).Text
Next
Next
For $x=0 to UBound($aSelected)
$nul = Execute('$Box'+$x+' = $EditForm.Controls.Add("TextBox")')
$nul = Execute('$Box'+$x+'.Text = $aSelected[$x]')
If $x=0
$nul = Execute('$Box'+$x+'.Left = 5')
Else
$nul = Execute('$Box'+$x+'.Left = $Box'+($x-1)+'.Right+5')
Endif
$nul = Execute('$Box'+$x+'.top = 20')
Next
$EditSaveButton = $EditForm.Controls.Add("ToolButton")
$EditSaveButton.Text = "Save"
$EditSaveButton.OnClick = "SaveListViewItem()"
$EditSaveButton.Width = 80
$EditSaveButton.Center()
$EditSaveButton.Top = $Box0.Bottom+15
$Form.Hide()
$EditForm.Show()
$EditForm.SetFocus()
While $EditForm.Visible
$Nul = Execute($EditForm.DoEvents)
Loop
$Form.Show()
Exit 0
EndFunction
Function SaveListViewItem()
For Each $Item In $ListView.SelectedItems
For $x = 0 to $ListView.Columns.Count
$nul = Execute('$info = $Box'+$x+'.Text')
$Item.SubItems($x).Text = $info
Next
Next
$EditForm.Hide()
EndFunction
Function PopulateListView()
For $x=1 to $columns
$nul = Execute('$Col'+$x+' = $Listview.Columns.Add("Col "+$x,$ListView.Width/$columns-1,2)')
Next
For $x=0 to 10
$row = $ListView.Items.Insert($x)
For $y=0 to $ListView.Columns.Count-1
$row.SubItems($y).Text = "Test "+$x
Next
Next
$ListView.SelectedItems = ""
EndFunction
|
Top
|
|
|
|
#203437 - 2011-11-02 05:20 AM
Re: dynamically creating textboxes
[Re: Dr_Rick]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
Here is your script with just a few minor changes, mostly to keep the console from ever opening, and with the novars option on. It took me forever to realize that there was a space in the "On" portion of the setoption that was killing me haha. But it seems to function now! Just needs the formatting done to match the parent form.
Attachments
iReport-II.kix (148 downloads) Description:
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 259 anonymous users online.
|
|
|