How to list tables in a form with Arcobject?

2267
1
06-14-2011 03:01 PM
New Contributor
I want to list Tables (Itables) in a form with ArcObjects, but I can't it.
I'm using this code.

Dim pMxDoc As IMxDocument
Set pMxDoc = Application.Document
Dim pTableCollection As ITableCollection
Dim pMap As IMap
Set pMap = pMxDoc.FocusMap
Set pTableCollection = pMap
Dim tabla As ITable
Dim ptabla As IFeatureLayer
Dim ntabla As String
For i = 0 To pTableCollection.TableCount - 1
Set tabla = pTableCollection.Table(i)
'Dim pName As IName
ntabla = tabla.                     '********* I can't get name of table
lista.AddItem (ntabla)
Next
Reply
0 Kudos
1 Reply
New Contributor
I want to list Tables (Itables) in a form with ArcObjects, but I can't it.
I'm using this code.

Dim pMxDoc As IMxDocument
Set pMxDoc = Application.Document
Dim pTableCollection As ITableCollection
Dim pMap As IMap
Set pMap = pMxDoc.FocusMap
Set pTableCollection = pMap
Dim tabla As ITable
Dim ptabla As IFeatureLayer
Dim ntabla As String
For i = 0 To pTableCollection.TableCount - 1
Set tabla = pTableCollection.Table(i)
'Dim pName As IName
ntabla = tabla.                     '********* I can't get name of table
lista.AddItem (ntabla)
Next


Cast the Table object to IClass and then cast it to IDataset to get the BrowseName of any class.
No need of implementing IName then.
Here is the code in C# for that:
IClass cls = tabla;
lista.Items.Add(TableName(cls as IDataset));

string TableName(IDataset ds)
{
            string[] v = ds.BrowseName.Split('.');
            string TableName = v[v.Length - 1].ToUpper();
            return TableName ;
}

Let me know if you still have any problem with that code.
Reply
0 Kudos