Bind a geodatabase table to a .NET control


Purpose
This sample demonstrates how to bind a geodatabase table and a .NET control. Additionally, it shows how editing and coded-value domains can be supported.

How to use

See How to use ArcGIS samples for help on compiling, setting up the debugger, and running the sample. If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

  1. Open the solution and build it.
  2. Run the sample to display the main window.
  3. The data in the table can be viewed by using the scroll bars and the current row can be changed by using the forward and back buttons on the navigation control at the bottom.
  4. Select the Use Coded Value Domain check box to show the domain value names for the Enabled column.
  5. All fields apart from geometry and Shape_Length can be edited by clicking the appropriate cell in the grid.
  6. The NAME field can also be edited by changing the text in the text box.
  7. Add a new row by typing values at the end of the grid or by clicking the Add Row button on the navigation control.
  8. Remove the current row by clicking the Delete button on the navigation control.

Additional information

This sample shows the binding of an entire ITable to a Microsoft DataGridView control and also a single IField to a Microsoft TextBox control. The solution contains the following two projects:
  • ArcDatabinding project (data binding implementation)—The TableWrapper class inherits from System.ComponentModel.BindingList to provide a default implementation of a list of objects (in this case, a list of IRows) that can be bound to a .NET control.

    The TableWrapper class also implements ITypedList to allow a control to query it for any properties required to correctly display the data in a control. As the individual fields in the ITable are not .NET properties, they must be made to look like properties of an IRow. This is achieved by creating a collection of "fake" properties with one for each field in the ITable. This is contained in the fakePropertiesList member and is used by the ITypedList implementation.

    The FieldPropertyDescriptor class implements the fake properties and inherits from System.ComponentModel.PropertyDescriptor. It overrides methods used to get type information for each IField in a given ITable, sets values for IFields when a new row is added, changes existing IField values, and deletes the values of IFields when an IRow is deleted. It also handles the type conversions required when showing the data in a .NET control.
  • DemoITableBinding project (sample application using the ArcDataBinding project)—This application shows a form containing a DataGridView, TextBox, and a BindingNavigater. The BindingNavigater allows the user to step through the data in the DataGridView and also add and remove rows. The TextBox shows the content of the FULL_NAME column of the current row in the DataGridView. Selecting the Use Coded Value Domain check box shows the coded-value domain value names in the Enabled column rather than the numeric values.

    The data binding is performed within the Form_Load event handler. Anew TableWrapper is created with a reference to the ITable being passed into the constructor. The TableWrapper instance is then used to set the DataSource property for a BindingSource object.

    The BindingSource acts as a common binding source for all the controls on the form and allows synchronization with the TableWrapper. Any changes made to data in one control attached to the BindingSource is reflected in all other controls that are also attached to the BindingSource. The controls update when the current row is changed using the BindingNavigator.

    This sample uses a BindingList with IRows being added to its object collection. A better implementation would be to implement all the interfaces required for a bindable list; thereby, allowing direct access to the wrapped ITable. The sample implementation loads the whole of the ITable into the BindingList, which results in a delay on startup but allows browsing of the ITable's contents without delays. Currently, no support is provided to show Raster or Blob Geodatabase field types.


ArcDataBinding/FieldPropertyDescriptor.cs The implementation of the FieldPropertyDescriptor class used to describe each IField in an ITable.
ArcDataBinding/TableWrapper.cs The implementation of the TableWrapper class used to bind an ITable to a control; inherits from the System.ComponentModel.BindingList class and ITypedList.
DemoITableBinding/MainWnd.cs The main form of the application.
Download the C# files
ArcDataBinding/FieldPropertyDescriptor.vb The implementation of the FieldPropertyDescriptor class used to describe each IField in an ITable.
ArcDataBinding/TableWrapper.vb The implementation of the TableWrapper class used to bind an ITable to a control; inherits from the System.ComponentModel.BindingList class and ITypedList.
DemoITableBinding/MainWind.vb The main form of the application.
Download the VB.NET files

Download the files for all languages




Development licensing Deployment licensing
Engine Developer Kit Engine
ArcGIS for Desktop Basic
ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced