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

Altering Listview columns width ?

 
Post new topic   Reply to topic    KiXforms Forum Index -> Advanced Scripting
View previous topic :: View next topic  
Author Message
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Wed Dec 03, 2008 5:19 pm    Post subject: Altering Listview columns width ? Reply with quote

I use the following functions to create Listview Forms and I find I need to create the columns before I add the data so have to make a guess at column width value for $CW0. I want to alter the column width once the data is added and the true width required enumerated.
I cant find a width property for .columns.
Is there a way of resetting the column width once the columns are created and the data is added or will I have to do a pass on the data first to pre-calculate the widths ?

Code:

$SCREENWIDTH=($SYSTEM.SCREEN.WORKINGAREA.RIGHT)
$SCREENHEIGHT=($SYSTEM.SCREEN.WORKINGAREA.BOTTOM)
$Font="Century Gothic"
$FontS=8 ;Font Size
$FntX=10  ;Font width multiplier
$LNHT=20  ;Font line height multiplier
$ICNW=48  ;Icon Width
$MAXHW=0.95 ;Max Height + Width of Form as proportion Screen Size

..

;------------------------------------------------------------------------
Function MakeForm($MN,$MI) ;Form Name,Form Index
Dim $Form,$LSTV
 $Form=$MN+'_'+'Form'+$MI
 $LSTV=$MN+'_'+'LstV'+$MI
 $ = execute("$$$Form = $$System.Form()")
 $ = execute("$$$Form.BorderStyle = 0")
 $ = execute("$$$Form.StartPosition = 1")
 $ = execute("$$$Form.FontName = $$Font")
 $ = execute("$$$Form.FontSize = $$FontS")
 $ = execute("$$$Form.minimizebox=-1")
 $ = execute("$$$Form.BorderStyle = 3")
 $ = execute("$$$Form.Width = ($$MaxDesW[$MN]*$$FNTX)+$$ICNW")

 $ = execute("$$$LSTV = $$System.ListView()")
 $ = execute("$$$LSTV.BorderStyle = 0")
 $ = execute("$$$LSTV.Left = 0")
 $ = execute("$$$LSTV.Text = $$item")
; $ = execute("$$$LSTV.FontName = $$Font")
; $ = execute("$$$LSTV.FontSize = $$FontS")
 $ = execute("$$$LSTV.AutoArrange = 'True'")
 $ = execute("$$$LSTV.Sorting = 1")
 $ = execute("$$$LSTV.MultiSelect = 0")
 $ = execute("$$$LSTV.ColumnClick = 'ListView_ColumnClick($MN,$MI,0)'")
 $ = execute("$$$LSTV.Click = 'ListView_ItemClick($MN,$MI)'")
 $ = execute("$$$LSTV.FullRowSelect = -1")  ;True
 $ = execute("$$$LSTV.View = $$System.View_Details")
 $ = execute("$$$LSTV.DockStyle = 5") ;fill
 $ = execute("$$$Form.Controls.Add($$$LSTV)")
$MenuFRM[$MI]=1 ; Form Created Flag
redim preserve $MenuItem[$MI]  ; Update array for counter of items in Form $MX
EndFunction
;------------------------------------------------------------------------
Function AddItem($MN,$MI,$MX,$Item) ;Form Name,Form Number,Unique Index,Line Text
 Dim $Form,$LSTV,$HT,$WI,$CW0
 $Form=$MN+'_'+'Form'+$MI
 $LSTV=$MN+'_'+'LstV'+$MI
 $MenuItem[$MI]=$MenuItem[$MI]+1
 If $MaxDesW[$MI]<len($Item)
  $MaxDesW[$MI]=len($Item) ;Determine column width required
 Endif
 $HT=($MenuItem[$MI] * $LNHT) + 30
 If  $HT > int($MAXHW*$SCREENHEIGHT)
  $HT = int($MAXHW*$SCREENHEIGHT)  ;Determine Useable form Height
 Endif
 $WI=($FNTX * $MaxDesW[$MI])+ $ICNW +8
 $CW0=($FNTX * $MaxDesW[$MI])
 If $WI > int($MAXHW*$SCREENWIDTH) ;Determine Useable form Width
  $WI = int($MAXHW*$SCREENWIDTH)
 Endif

If $MenuFRM[$MI]=1  ; Form exists Flag but no content
 $ = execute('$$$LSTVC0 = $$$LSTV.Columns.Add($$System.ColumnHeader("",$CW0,$$System.HorizontalAlignment_Right))') ; <- Initial Column Width
 $ = execute('$$$LSTVC1 = $$$LSTV.Columns.Add($$System.ColumnHeader("",$ICNW,$$System.HorizontalAlignment_Center))')
 $ = execute('$$$LSTVC1 = $$$LSTV.Columns.Add($$System.ColumnHeader("",$ICNW,$$System.HorizontalAlignment_Left))')
 $MenuFRM[$MI]=2
Endif
If $MenuFRM[$MI]=2  ; Form exists Flag with columns
 $ = execute('$$$Form.Height = $HT')
 $ = execute('$$$Form.Width = $WI')
 $ = execute('$$$LSTV.Width = $WI-8')
 $ = execute('$$$LSTV.Height = $HT-$LNHT')
 $ = execute('$$LSTVC0 = $$LSTV.Items.Add($$System.ListViewItem)')

 $ = execute('$$LSTVC0 = $$$LSTV.Items.Add($$System.ListViewItem("$item"))')
 $ = execute('$$LSTVC1 = $$LSTVC0.Items.item($MI).subitems.Add($$System.ListViewSubItem($MenuItem[$MI]))')
 $ = execute('$$LSTVC2 = $$LSTVC0.Items.item($MI).subitems.Add($$System.ListViewSubItem($MX))')
EndIf
EndFunction
[/code]
________
Critical illness insurance dicussion


Last edited by MACE1 on Fri Feb 18, 2011 5:21 pm; edited 1 time in total
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: Thu Dec 04, 2008 1:40 pm    Post subject: Reply with quote

Hi Mace,

It has been so long, I cant remember for sure but I think you can set a column width to the longest length if an item in that column with somthing like:

This is one of those things you must do after the Columns are populated.

Code:

$ListView.Columns(0).Width = -1  ;Column 0
$ListView.Columns(1).Width = -1  ;Column 1
$ListView.Columns(2).Width = -1  ;Column 2

_________________
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
benny69
KiXforms Advocate
KiXforms Advocate


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

PostPosted: Thu Dec 04, 2008 3:43 pm    Post subject: Reply with quote

I found an old Example of working with a ListView, Let me if works for you:

Code:

;region Setup Variables
$Version = 'Build(1.0.0.1)'
$System = CreateObject('Kixtart.System')
Break on
If Not $System
  $ = MessageBox("KiXforms Not Initiated. This Script Will Now Close.", "Error", 16)
  Quit()
EndIf
;endregion

;region Main Form
$Form = $System.Form()
$Form.Text = 'Basic Form $Version'
$Form.Size = 600, 276

$StatusBar = $Form.Controls.StatusBar()

$ProgressBar = $StatusBar.Controls.ProgressBar()
$ProgressBar.BorderStyle = "FixedSingle"
$ProgressBar.Height = 14
$ProgressBar.Left = $StatusBar.Width - 115
$ProgressBar.Top = 5
$ProgressBar.Visible = "False"

$ListView = $Form.Controls.ListView()
$ListView.CheckBoxes = "True"
$ListView.Dock = "Top"

$BottomPanel = $Form.Controls.Panel()
$BottomPanel.Dock = "Fill"
$BottomPanel.DockPadding = 5

$OKButton = $BottomPanel.Controls.Button()
$OKButton.Height = 21
$OKButton.Left = ($BottomPanel.ClientWidth /2) - 80
$OKButton.OnClick = "EvaluateCheckedItems()"
$OKButton.Text = "OK"
$OKButton.Width = 75

$CloseButton = $BottomPanel.Controls.Button()
$CloseButton.Height = 21
$CloseButton.Left = $OKButton.Right + 10
$CloseButton.OnClick = "OnExit()"
$CloseButton.Text = "Close"
$CloseButton.Width = 75

$Column0 = $ListView.Columns.Add("Entry", 100, $System.HorizontalAlignment.Center)
$Column1 = $ListView.Columns.Add("Sub-Entry", 100, $System.HorizontalAlignment.Center)
$Column2 = $ListView.Columns.Add("Sub-Entry", 100, $System.HorizontalAlignment.Center)

For $i = 1 to 10
  $Item = $ListView.Items.Add("Entry " + $i)
  $Item.SubItems(1).Text = "Sub-Entry " + $i
  $Item.SubItems(2).Text = "Sub-Sub-Entry " + $i
Next

$ListView.Items.Checked = "True"
$ListView.Columns(0).Width = -1  ;Set Column 0 Width to length of longest Item in Column 0
$ListView.Columns(1).Width = -1  ;Set Column 1 Width to length of longest Item in Column 1
$ListView.Columns(2).Width = -1  ;Set Column 1 Width to length of longest Item in Column 1

$Form.Center
$Form.Show()

;region Startup
;call some function
;endregion

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

;region Functions
Function EvaluateCheckedItems()
     
  $ProgressBar.Visible = "True"
  For Each $Item in $ListView.Items
    $Entry = $item.SubItems(0).Text
    If $Item.Checked = 0
      ? $Entry + " Not Checked"
    Else
      ? $Entry + " Checked"
    EndIf
    AdvanceProgressBar(10, $Entry)
  Next
  AdvanceProgressBar(0, "")
  $ProgressBar.Visible = "False"
     
EndFunction

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

Function OnExit()
  Quit()
EndFunction
;endregion

_________________
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
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Mon Jan 05, 2009 10:31 am    Post subject: Reply with quote

Very Happy
-1 is the key for all derrivations.
Thanks, Saved me unnecessary work.
________
Ferrari Tipo 500 Specifications
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Advanced Scripting 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