@@ -169,32 +169,34 @@ private void AddFilter(Window win)
169169 X = 2
170170 } ;
171171
172- var filterLabelWidth = filterLabel . Text . Length + 1 ;
173172 var filterField = new TextField ( string . Empty )
174173 {
175174 X = Pos . Right ( filterLabel ) + 1 ,
176175 Y = Pos . Top ( filterLabel ) ,
177176 CanFocus = true ,
178- Width = Dim . Fill ( ) - filterLabelWidth
177+ Width = Dim . Fill ( ) - filterLabel . Text . Length
179178 } ;
180179
181180 var filterErrorLabel = new Label ( string . Empty )
182181 {
183182 X = Pos . Right ( filterLabel ) + 1 ,
184183 Y = Pos . Top ( filterLabel ) + 1 ,
185184 ColorScheme = Colors . Base ,
186- Width = Dim . Fill ( ) - filterLabelWidth
185+ Width = Dim . Fill ( ) - filterLabel . Text . Length
187186 } ;
188187
189- EventHandler < ustring > filterChanged = ( object sender , ustring e ) =>
188+ filterField . Changed + = ( object sender , ustring e ) =>
190189 {
190+ // NOTE: `ustring e` seems to contain the text _before_ the added character...
191+ // so we convert the `sender` into a TextField and grab the text from that.
192+ string filterText = ( sender as TextField ) ? . Text ? . ToString ( ) ;
191193 try
192194 {
193195 filterErrorLabel . Text = " " ;
194196 filterErrorLabel . ColorScheme = Colors . Base ;
195197 filterErrorLabel . Redraw ( filterErrorLabel . Bounds ) ;
196198
197- var itemList = GridViewHelpers . FilterData ( _itemSource . GridViewRowList , e . ToString ( ) ) ;
199+ List < GridViewRow > itemList = GridViewHelpers . FilterData ( _itemSource . GridViewRowList , filterText ) ;
198200 _listView . Source = new GridViewDataSource ( itemList ) ;
199201 }
200202 catch ( Exception ex )
@@ -206,8 +208,6 @@ private void AddFilter(Window win)
206208 }
207209 } ;
208210
209- filterField . Changed += filterChanged ;
210-
211211 win . Add ( filterLabel , filterField , filterErrorLabel ) ;
212212 }
213213
0 commit comments