/// <summary> /// This method gets the selectd layer, casts it into a feature layer /// Therefater accesses the table and binds it to a .NET DataGrid View Control /// </summary> public void bindTable() { try { IFeatureLayer iFeatureLayer = (IFeatureLayer)m_iLayer; //open the Geodatabase table ITable foundITable = iFeatureLayer.FeatureClass as ITable; if (null != foundITable) { // Bind dataset to the binding source tableWrapper = new ArcDataBinding.TableWrapper(foundITable); bindingSource1.DataSource = tableWrapper; // Bind binding source to grid. Alternatively it is possible to bind TableWrapper // directly to the grid to this offers less flexibility dtgAttributeTable.DataSource = bindingSource1; // Bind binding source to text box, we are binding the NAME // field. //txtBoxBinding = new Binding("Text", bindingSource1, "FACILITYNAME"); //textBox1.DataBindings.Add(txtBoxBinding); } } catch (COMException COMex) { MessageBox.Show("Error " + COMex.ErrorCode.ToString() + ": " + COMex.Message); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } }
private void MainWnd_Load(object sender, EventArgs e) { // Get workspace and open mdb file IWorkspaceFactory2 wkspcFactory = (IWorkspaceFactory2)new FileGDBWorkspaceFactoryClass(); IFeatureWorkspace wkspc = wkspcFactory.OpenFromFile( @"..\..\..\..\..\..\data\SanFrancisco\SanFrancisco.gdb", Handle.ToInt32()) as IFeatureWorkspace; //open the Geodatabase table ITable foundITable = wkspc.OpenFeatureClass("Parks") as ITable; if (null != foundITable) { // Bind dataset to the binding source tableWrapper = new ArcDataBinding.TableWrapper(foundITable); bindingSource1.DataSource = tableWrapper; // Bind binding source to grid. Alternatively it is possible to bind TableWrapper // directly to the grid to this offers less flexibility dataGridView1.DataSource = bindingSource1; // Bind binding source to text box, we are binding the NAME // field. txtBoxBinding = new Binding("Text", bindingSource1, "NAME"); textBox1.DataBindings.Add(txtBoxBinding); } }
private void MainWnd_Load(object sender, EventArgs e) { // Get workspace and open mdb file IWorkspaceFactory2 wkspcFactory = (IWorkspaceFactory2) new FileGDBWorkspaceFactoryClass(); string filePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); filePath = System.IO.Path.Combine(filePath, @"ArcGIS\data\SanFrancisco\SanFrancisco.gdb"); IFeatureWorkspace wkspc = wkspcFactory.OpenFromFile(filePath, Handle.ToInt32()) as IFeatureWorkspace; //open the Geodatabase table ITable foundITable = wkspc.OpenFeatureClass("Parks") as ITable; if (null != foundITable) { // Bind dataset to the binding source tableWrapper = new ArcDataBinding.TableWrapper(foundITable); bindingSource1.DataSource = tableWrapper; // Bind binding source to grid. Alternatively it is possible to bind TableWrapper // directly to the grid to this offers less flexibility dataGridView1.DataSource = bindingSource1; // Bind binding source to text box, we are binding the NAME // field. txtBoxBinding = new Binding("Text", bindingSource1, "NAME"); textBox1.DataBindings.Add(txtBoxBinding); } }
private void bindTableToGrid() { //get meters featureclass if (m_iFeatureClass == null) { m_iFeatureClass = getFeatureClass(); } //get the attributes table for the particular feature class ITable iTable = (ITable)m_iFeatureClass; if (null != iTable) { // Bind dataset to the binding source tableWrapper = new ArcDataBinding.TableWrapper(iTable); tableWrapper.UseCVDomains = true; bindingSource1.DataSource = tableWrapper; // Bind binding source to grid. Alternatively it is possible to bind TableWrapper // directly to the grid to this offers less flexibility dataGridView1.DataSource = bindingSource1; // Bind binding source to text box, we are binding the NAME // field. txtBoxBinding = new Binding("Text", bindingSource1, "OBJECTID"); textBox1.DataBindings.Add(txtBoxBinding); //Bind Source to cbo? IFields fields = m_iFeatureClass.Fields; IField field = null; for (int i = 0; i < fields.FieldCount; i++) { // Get the field at the given index. field = fields.get_Field(i); if (field.Name != field.AliasName) { ComboboxItem item = new ComboboxItem(); item.Text = field.AliasName; item.Value = field.Name; cboFields.Items.Add(item); } } //cboFields.DataBindings.Add(txtBoxBinding); } }