How to add custom table with data from a datatable vb.net

How to add custom table with data from a datatable vb.net

SandmanINV
Advocate Advocate
1,471 Views
1 Reply
Message 1 of 2

How to add custom table with data from a datatable vb.net

SandmanINV
Advocate
Advocate

Hi evveryone, 

Like my topic title. How can i create a custom table in inventor drawing with data from a datatable of vb.net ?

In vb.net, if I want create datagridview from datatable, just "datagridview1.datasource = datatable".

But in inventor drawing, i dont know how.

Thank you very much.

0 Likes
Accepted solutions (1)
1,472 Views
1 Reply
Reply (1)
Message 2 of 2

JelteDeJong
Mentor
Mentor
Accepted solution

The datatable  for datagridview1.datasource is usaly some sort of list of objects. (i dont know what kind of list you use but the all all work more or less the same.) in iLogic i created a list of person objects and used that to show how to create a table with it.

[iLogic]

Public Class test
	Public Sub Main()
		'creat a list
		Dim personList As List(Of Person) = New List(Of Person)()
		personList.Add(New Person("Jhon", "Do", "20"))
		personList.Add(New Person("Albert", "Heijn", "26"))
		personList.Add(New Person("Mariska", "Smith", "18"))
	
		'get the sheet 
		Dim ThisApplication As Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
		Dim doc As DrawingDocument = ThisApplication.ActiveDocument
		Dim oSheet As Sheet = doc.ActiveSheet
	
		'add table to sheet
		Dim insertPoint = ThisApplication.TransientGeometry.CreatePoint2d(10, 10)
		Dim tableTitle As String = "Persons table"
		Dim headerTitles() As String = {"name", "last name", "age"}
		Dim table As CustomTable = oSheet.CustomTables.Add(tableTitle, insertPoint, headerTitles.Count, personList.Count, headerTitles)
	
		'fill the table
		For index = 1 To table.Rows.Count
			Dim row As Row = table.Rows.Item(index)
			Dim person As Person = personList(index - 1)
			row.Item(1).Value = person.Name
			row.Item(2).Value = person.lastname
			row.Item(3).Value = person.age
		Next
	End Sub
End Class

Public Class Person
    Public Sub New(name, lastname, age)
        Me.Name = name
        Me.lastname = lastname
        Me.age = age
    End Sub
    Public Property name As String
    Public Property lastname As String
    Public Property age As String
End Class

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes