1 | //----------------------------------------------------------------------------- |
---|
2 | // wx.NET/Samples - ListView.cs |
---|
3 | // |
---|
4 | // wx.NET "ListView" sample. |
---|
5 | // |
---|
6 | // Written by Alexander Olk (xenomorph2@onlinehome.de) |
---|
7 | // (C) 2004 Alexander Olk |
---|
8 | // Licensed under the wxWidgets license, see LICENSE.txt for details. |
---|
9 | // |
---|
10 | // $Id$ |
---|
11 | //----------------------------------------------------------------------------- |
---|
12 | |
---|
13 | using System; |
---|
14 | using System.Drawing; |
---|
15 | |
---|
16 | namespace wx.SampleListView |
---|
17 | { |
---|
18 | public class ListViewFrame : Frame |
---|
19 | { |
---|
20 | enum Cmd |
---|
21 | { |
---|
22 | About, |
---|
23 | Quit |
---|
24 | } |
---|
25 | |
---|
26 | //--------------------------------------------------------------------- |
---|
27 | |
---|
28 | public TextCtrl textCtrl; |
---|
29 | |
---|
30 | //--------------------------------------------------------------------- |
---|
31 | |
---|
32 | public ListViewFrame(string title, Point pos, Size size) |
---|
33 | : base(title, pos, size) |
---|
34 | { |
---|
35 | // Set the window icon and status bar |
---|
36 | |
---|
37 | Icon = new wx.Icon("../Samples/ListView/mondrian.png"); |
---|
38 | |
---|
39 | CreateStatusBar(); |
---|
40 | StatusText = "Welcome to the ListView Sample!"; |
---|
41 | |
---|
42 | Menu menuFile = new Menu(); |
---|
43 | menuFile.AppendWL( (int)Cmd.About, "&About", new EventListener( OnAbout ) ); |
---|
44 | menuFile.AppendSeparator(); |
---|
45 | menuFile.AppendWL( (int)Cmd.Quit, "E&xit\tAlt-X", "Quit this program", new EventListener( OnQuit) ); |
---|
46 | |
---|
47 | MenuBar menuBar = new MenuBar(); |
---|
48 | menuBar.Append( menuFile, "&File" ); |
---|
49 | MenuBar = menuBar; |
---|
50 | |
---|
51 | textCtrl = new TextCtrl(this, -1, "", wxDefaultPosition, wxDefaultSize, |
---|
52 | TextCtrl.wxTE_MULTILINE | TextCtrl.wxTE_READONLY | TextCtrl.wxSUNKEN_BORDER ); |
---|
53 | |
---|
54 | Log.SetActiveTarget( textCtrl ); |
---|
55 | |
---|
56 | MyListView mlv = new MyListView( this ); |
---|
57 | |
---|
58 | BoxSizer bSizer = new BoxSizer( Orientation.wxVERTICAL ); |
---|
59 | bSizer.Add( mlv, 1, Stretch.wxGROW ); |
---|
60 | bSizer.Add( textCtrl, 0, Stretch.wxGROW ); |
---|
61 | |
---|
62 | Sizer = bSizer; |
---|
63 | } |
---|
64 | |
---|
65 | //--------------------------------------------------------------------- |
---|
66 | |
---|
67 | public void OnAbout( object sender, Event e ) |
---|
68 | { |
---|
69 | MessageDialog.MessageBox( "wx.NET ListView sample\n2004 by Alexander Olk", "About", |
---|
70 | Dialog.wxOK | Dialog.wxICON_INFORMATION ); |
---|
71 | } |
---|
72 | |
---|
73 | //--------------------------------------------------------------------- |
---|
74 | |
---|
75 | public void OnQuit( object sender, Event e ) |
---|
76 | { |
---|
77 | Close(); |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | //--------------------------------------------------------------------- |
---|
82 | |
---|
83 | public class MyListView : ListView |
---|
84 | { |
---|
85 | public MyListView( Window parent ) |
---|
86 | : base( parent, -1, wxDefaultPosition, wxDefaultSize, ListCtrl.wxLC_REPORT | ListCtrl.wxLC_EDIT_LABELS ) |
---|
87 | { |
---|
88 | |
---|
89 | InsertColumn( 0, "First Column" ); |
---|
90 | SetColumnWidth( 0, 200 ); |
---|
91 | |
---|
92 | ListItem itemCol = new ListItem(); |
---|
93 | itemCol.Text = "Second Column"; |
---|
94 | itemCol.Align = ListCtrl.wxLIST_FORMAT_CENTER; |
---|
95 | itemCol.Width = 300; |
---|
96 | InsertColumn( 1, itemCol ); |
---|
97 | |
---|
98 | for ( int i = 0; i < 200; ++i ) |
---|
99 | { |
---|
100 | string buf = "Col 1 Item " + i; |
---|
101 | int tmp = InsertItem( i, buf, 0); |
---|
102 | SetItemData( tmp, i ); |
---|
103 | |
---|
104 | buf = "Col 2 Item " + i; |
---|
105 | SetItem( i, 1, buf ); |
---|
106 | } |
---|
107 | |
---|
108 | Log.LogMessage( "Items created..." ); |
---|
109 | |
---|
110 | ColumnClick += new EventListener( OnColumnClick ); |
---|
111 | ItemSelect += new EventListener( OnItemSelect ); |
---|
112 | ColumnRightClick += new EventListener( OnColumnRightClick ); |
---|
113 | } |
---|
114 | |
---|
115 | //--------------------------------------------------------------------- |
---|
116 | |
---|
117 | public void OnColumnClick( object sender, Event e ) |
---|
118 | { |
---|
119 | ListEvent le = e as ListEvent; |
---|
120 | |
---|
121 | Log.LogMessage( "Clicked column header " + le.Column ); |
---|
122 | } |
---|
123 | |
---|
124 | //--------------------------------------------------------------------- |
---|
125 | |
---|
126 | public void OnItemSelect( object sender, Event e ) |
---|
127 | { |
---|
128 | ListEvent le = e as ListEvent; |
---|
129 | |
---|
130 | Log.LogMessage( "Value 1st field of selected item: " + le.Text ); |
---|
131 | |
---|
132 | ListItem info = new ListItem(); |
---|
133 | info.Id = le.Index; |
---|
134 | info.Column = 1; |
---|
135 | info.Mask = ListCtrl.wxLIST_MASK_TEXT; |
---|
136 | |
---|
137 | GetItem( ref info ); |
---|
138 | |
---|
139 | Log.LogMessage( "Value of 2nd field of selected item: " + info.Text ); |
---|
140 | } |
---|
141 | |
---|
142 | //--------------------------------------------------------------------- |
---|
143 | |
---|
144 | public void OnColumnRightClick( object sender, Event e ) |
---|
145 | { |
---|
146 | ListEvent le = e as ListEvent; |
---|
147 | |
---|
148 | Log.LogMessage( "Right clicked column header " + le.Column ); |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | //--------------------------------------------------------------------- |
---|
153 | |
---|
154 | public class ListViewApp : wx.App |
---|
155 | { |
---|
156 | public override bool OnInit() |
---|
157 | { |
---|
158 | ListViewFrame frame = new ListViewFrame("ListView wxWidgets Sample", new Point(10, 100), new Size(650,340)); |
---|
159 | frame.Show(true); |
---|
160 | |
---|
161 | return true; |
---|
162 | } |
---|
163 | |
---|
164 | //--------------------------------------------------------------------- |
---|
165 | |
---|
166 | [STAThread] |
---|
167 | static void Main() |
---|
168 | { |
---|
169 | ListViewApp app = new ListViewApp(); |
---|
170 | app.Run(); |
---|
171 | } |
---|
172 | } |
---|
173 | } |
---|