[Python.NET] ListView bug?
Guy Robinson
guy at r-e-d.co.nz
Wed Jun 1 14:05:02 CEST 2005
Ok, my fault :-( This works:
data = [("one","test one"),("two","test two"), ("three","test three")]
for index in range(len(data)):
temp = WF.ListViewItem(str(index))
temp.Text = data[index][0]
temp.SubItems.Add(data[index][1])
self.listView.Items.Add(temp)
Guy
Guy Robinson wrote:
> Find attached script for a windows.Form. Is this a bug? When loading the
> data into the listview from a list of tuples:
>
> data = [("one","test one"),("two","test two"), ("three","test three")]
> for item in data:
> temp = WF.ListViewItem(item[0])
> temp.SubItems.Add(item[1])
> self.listView.Items.Add(temp)
>
> The rows are filled with the first and second characters of the first
> string rather than the relevant tuple strings.
>
> Winforms is pretty cool otherwise.
>
> Guy
>
>
> ------------------------------------------------------------------------
>
> import CLR
> from CLR import System
>
> import CLR.System.Windows.Forms as WF
> from CLR.System.Drawing import Size, Point, Color
>
> class ScriptForm(WF.Form):
> """A simple hello world app that demonstrates the essentials of
> WF programming and event-based programming in Python."""
>
> def __init__(self):
> self.Text = "Python scripting for the Revit API"
> #self.AutoScaleBaseSize = Size(5, 13)
> self.ClientSize = Size(500, 300)
> h = WF.SystemInformation.CaptionHeight
> self.MinimumSize = Size(300, (100 + h))
> self.FormBorderStyle = WF.FormBorderStyle.FixedDialog
> self.MinimizeBox = False
> self.MaximizeBox = False
> self.StartPosition = WF.FormStartPosition.CenterScreen
> self.components = System.ComponentModel.Container()
>
> # Create the ListView
> self.listView = WF.ListView()
> self.listView.Location = Point(5,5)
> self.listView.Width = 370
> self.listView.Height = self.ClientSize.Height-10
> self.listView.TabIndex = 0
> self.formatLV()
> self.loaddata()
>
> # Create the run button
> self.runBut = WF.Button()
> self.runBut.Location = Point(400, 100)
> self.runBut.BackColor = Color.GreenYellow
> self.runBut.TabIndex = 1
> self.runBut.Text = "Run Script"
>
> # Create the Cancel button
> self.CanBut = WF.Button()
> self.CanBut.Location = Point(400, 150)
> self.CanBut.TabIndex = 2
> self.CanBut.Text = "Cancel"
>
> # Register the event handlers
> self.runBut.Click += self.runScript_Click
> self.CanBut.Click += self.Cancel_Click
>
> # Add the controls to the form
> self.Controls.Add(self.listView)
> self.Controls.Add(self.runBut)
> self.Controls.Add(self.CanBut)
>
> def runScript_Click(self, sender, args):
> """ Get and Run the selected script"""
> WF.MessageBox.Show("Run script")
> #return "script"
>
> def Cancel_Click(self, sender, args):
> """Cancel don't run anything"""
> #return "cancel"
> self.components.Dispose()
> WF.Form.Dispose(self)
> self.Close()
>
> def formatLV(self):
> self.listView.View = WF.View.Details
> self.listView.LabelEdit = False
> self.listView.AllowColumnReorder = False
> self.listView.GridLines = True
> self.listView.FullRowSelect = True
> self.listView.Sorting = WF.SortOrder.Ascending
> #now do columns
> self.listView.Columns.Add("Script Name", 100,WF.HorizontalAlignment.Left)
> self.listView.Columns.Add("Description", 266,WF.HorizontalAlignment.Left)
>
> def loaddata(self):
> data = [("one","test one"),("two","test two"), ("three","test three")]
> for item in data:
> temp = WF.ListViewItem(item[0])
> temp.SubItems.Add(item[1])
> self.listView.Items.Add(temp)
>
> def run(self):
> WF.Application.Run(self)
> self.components.Dispose()
> WF.Form.Dispose(self)
> self.Close()
>
> def main():
> ScriptForm().run()
>
>
> if __name__ == '__main__':
> main()
>
>
>
> ------------------------------------------------------------------------
>
> _________________________________________________
> Python.NET mailing list - PythonDotNet at python.org
> http://mail.python.org/mailman/listinfo/pythondotnet
--
Robinson eDesign, P/F: +64 7 866 0626
Rings Beach, M: 021 238 0839 -ltd coverage
RD2, E: guy at r-e-d.co.nz
Whitianga.
New Zealand
More information about the PythonDotNet
mailing list