Select to view content in your preferred language

VB.NET Add Relates using IMapTableInfo

4541
4
Jump to solution
05-17-2016 12:41 PM
Corbinde_Bruin
Frequent Contributor

Hi everyone,

I've come across an issue with MXD relates and I need a .NET solution to add them to a map. I started with a sample that uses ArcObjects, but I hit a stumbling block with the IMapTableInfo Interface. I have no idea how to get or set this object. I've read the documentation page, but it doesn't seem to have any useful information (that I understood).

Has anyone used this object?

Does anyone have code samples using IMapTableInfo that can help me?

Does anyone have code samples that can help me add MXD relates?

This is the code sample I've already found (the problem being that it expects a valid IMapTableInfo object as a parameter):

IRelateInfos pRIs = null; 
IRelateInfo pRI = null;
pRIs = pMTI.RelateInfos;
if (pRIs == null) 
{
  Console.WriteLine(“No relationship is available”); 
  return;
}
for (int j = 0; j < pRIs.Count; j++)
{
  pRI = pRIs.get_Element(j);
  Console.WriteLine(pRI.Name + “, " + pRI.RelationshipID + “, ” + pRI.RelatedTableID + “\n”);
}

I've also explored Python and geoprocessing as options. There is no method to "Add Relates" in ArcMap. It does exist in ArcGIS Pro, but that product is basically nonfunctional.

0 Kudos
1 Solution

Accepted Solutions
YuanLiu
Deactivated User

If you are trying to "relate a table to a layer in ArcMap", the VBA sample at ArcObjects 10 VBA SDK Help  might be helpful. I have not tried it myself, but the method should also work for .NET.

View solution in original post

4 Replies
Corbinde_Bruin
Frequent Contributor

The only thing I've tried since I posted was to cast a valid IStandaloneTable object as a IMapTableInfo and that did not work.

0 Kudos
DuncanHornby
MVP Notable Contributor

Just had a look at the API. Looking at this page​ it seems to be related to Mapserver​, are you trying to use this in an addin for say desktop? If so I don't think it will work. It was not clear if you are developing a desktop solution or some sort of server application?

YuanLiu
Deactivated User

If you are trying to "relate a table to a layer in ArcMap", the VBA sample at ArcObjects 10 VBA SDK Help  might be helpful. I have not tried it myself, but the method should also work for .NET.

Corbinde_Bruin
Frequent Contributor

I got it working with Yuan Liu's suggestion. Thank you very much. I had not previously found that sample. Just be wary that some of the syntax is wrong in some in the VB.NET sample. You have to piece it together from the C# and VBA samples. Then read the documentation on IMemoryRelationshipClassFactory as well. That helped me to discover I had switched my field names for the Primary and Foreign keys when I was receiving a generic COM Error.

To clarify, this was to develop a .NET addin for ArcMap 10.3 (Desktop).

0 Kudos