|
99 | 99 |
|
100 | 100 | <xref:System.ComponentModel.BindingList`1> supports factory-created instances through the extensible <xref:System.ComponentModel.BindingList`1.AddNew*> method. (This same type of extensibility is also found in other classes, such as <xref:System.Windows.Forms.BindingSource>) In addition, since this class implements the <xref:System.ComponentModel.ICancelAddNew> interface, it enables transactional commits or rollbacks of the new item through the <xref:System.ComponentModel.BindingList`1.EndNew*> and <xref:System.ComponentModel.BindingList`1.CancelNew*> methods. |
101 | 101 |
|
102 | | -
|
103 | | -
|
104 | 102 | ## Examples |
105 | 103 | The following code example demonstrates binding to a <xref:System.ComponentModel.BindingList`1> component containing a business object. This is a complete example that contains a `Main` method. |
106 | 104 |
|
|
173 | 171 | ## Remarks |
174 | 172 | The following table shows initial property values for an instance of <xref:System.ComponentModel.BindingList`1> class. |
175 | 173 |
|
176 | | -|Property|Initial Value| |
177 | | -|--------------|-------------------| |
178 | | -|<xref:System.ComponentModel.BindingList`1.AllowEdit*>|`true`| |
179 | | -|<xref:System.ComponentModel.BindingList`1.AllowNew*>|`true` if the list type has a parameterless constructor; otherwise, `false`.| |
180 | | -|<xref:System.ComponentModel.BindingList`1.AllowRemove*>|`true`| |
181 | | -|<xref:System.ComponentModel.BindingList`1.RaiseListChangedEvents*>|`true`| |
182 | | -
|
183 | | -
|
| 174 | +| Property | Initial Value | |
| 175 | +|--------------------------------------------------------------------|---------------| |
| 176 | +| <xref:System.ComponentModel.BindingList`1.AllowEdit*> | `true` | |
| 177 | +| <xref:System.ComponentModel.BindingList`1.AllowNew*> | `true` if the list type has a parameterless constructor; otherwise, `false`. | |
| 178 | +| <xref:System.ComponentModel.BindingList`1.AllowRemove*> | `true` | |
| 179 | +| <xref:System.ComponentModel.BindingList`1.RaiseListChangedEvents*> | `true` | |
184 | 180 |
|
185 | 181 | ## Examples |
186 | 182 | The following code example demonstrates how to construct a new <xref:System.ComponentModel.BindingList`1>. For the complete example, see the <xref:System.ComponentModel.BindingList`1> class overview topic. |
|
302 | 298 |
|
303 | 299 | For more information about supplying custom new item functionality, see the <xref:System.ComponentModel.BindingList`1.AddNew*> method. For more information about how to handle events, see [Handling and Raising Events](/dotnet/standard/events/). |
304 | 300 |
|
305 | | -
|
306 | | -
|
307 | 301 | ## Examples |
308 | 302 | The following code example demonstrates how to handle the <xref:System.ComponentModel.BindingList`1.AddingNew> event. For the complete example, see the <xref:System.ComponentModel.BindingList`1> class overview topic. |
309 | 303 |
|
|
362 | 356 | ## Remarks |
363 | 357 | The <xref:System.ComponentModel.BindingList`1.AddNew*> method adds a new item to the collection represented by the <xref:System.Collections.ObjectModel.Collection`1.Items> property. To add a new item, the following logic is used: |
364 | 358 |
|
365 | | -1. The <xref:System.ComponentModel.BindingList`1.AddingNew> event is automatically raised. |
| 359 | +1. The <xref:System.ComponentModel.BindingList`1.AddingNew> event is automatically raised. |
366 | 360 |
|
367 | | - This event can be programmatically handled to construct a new custom item. This is accomplished in the event handler by setting the <xref:System.ComponentModel.AddingNewEventArgs.NewObject> property of the <xref:System.ComponentModel.AddingNewEventArgs> parameter to the new item. |
| 361 | + This event can be programmatically handled to construct a new custom item. This is accomplished in the event handler by setting the <xref:System.ComponentModel.AddingNewEventArgs.NewObject> property of the <xref:System.ComponentModel.AddingNewEventArgs> parameter to the new item. |
368 | 362 |
|
369 | | - Otherwise, the new item is automatically created through its public parameterless constructor. |
| 363 | + Otherwise, the new item is automatically created through its public parameterless constructor. |
370 | 364 |
|
371 | | -2. The position of the new item is tracked, but it is not added to the list until one of the following conditions are met: |
| 365 | +2. The position of the new item is tracked, but it is not added to the list until one of the following conditions are met: |
372 | 366 |
|
373 | | - - The item is explicitly committed by a call to <xref:System.ComponentModel.BindingList`1.EndNew*>. |
374 | | -
|
375 | | - - The item is implicitly committed by some other operation that changed the contents of the list, such as an insertion or removal of an item. |
| 367 | + - The item is explicitly committed by a call to <xref:System.ComponentModel.BindingList`1.EndNew*>. |
| 368 | + - The item is implicitly committed by some other operation that changed the contents of the list, such as an insertion or removal of an item. |
376 | 369 |
|
377 | 370 | In contrast, calling the <xref:System.ComponentModel.BindingList`1.CancelNew*> method before the item is committed will cause the new item to be discarded. |
378 | 371 |
|
379 | 372 | This method raises the <xref:System.ComponentModel.BindingList`1.ListChanged> event when the new item is committed. |
380 | 373 |
|
381 | | -
|
382 | | -
|
383 | 374 | ## Examples |
384 | 375 | The following code example demonstrates how to use the <xref:System.ComponentModel.BindingList`1.AddNew*> method. <xref:System.ComponentModel.BindingList`1>. For the complete example, see the <xref:System.ComponentModel.BindingList`1> class overview topic. |
385 | 376 |
|
|
0 commit comments