Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
prabhuappu
Creator II
Creator II

Get objects used in a container using OCX in C#?

Hi,

I'm trying to get the list of objects used in a container object using C#.

But there is no GetProperties() function for SheetObjects in OCX library.

i found the below code to set the container objects using vb Macro. it has a method to get the contained objects.

Is there any method to achieve this in C#?

Set ContainerObj = ActiveDocument.Sheets("Main").CreateContainer

set ContProp=ContainerObj.GetProperties

ContProp.ContainedObjects.Add

ContProp.SingleObjectMode=1

ContProp.SingleObjectStyle=1

ContProp.ShowObjectTypeIcons=true

ContProp.ContainedObjects.Add

ContProp.ContainedObjects.Item(0).Id = "Document\CH03"

ContProp.ContainedObjects.Item(0).Text.v = "Bar"

ContProp.ContainedObjects.Add

ContProp.ContainedObjects.Item(1).Id = "Document\CH01"

ContProp.ContainedObjects.Item(1).Text.v = "Mekko"

ContainerObj.SetProperties ContProp

Thanks in Advance.

5 Replies
Jeff_Koch
Employee
Employee

Hi,

Here is a routine I wrote for one of my customer to create a container object and populate it. It is a VB.Net snippet and you should be able to use the same object reference to get the object id’s of the objects in the container then use those to get the object’s properties.

Regards,

Jeff

Private Sub addObjectToContainer()

Dim ListboxObj As QlikView.ListBox

Dim LBProp As QlikView.IListBoxProperties

Dim LBID As String

Dim Fields(6) As String

Dim ContainerObj As QlikView.Container

Dim ContProp As QlikView.IContainerProperties

Dim ContFrame As QlikView.IFrame

Dim i As Integer

'[ init field list of Data model fields we want in list boxes

Fields(0) = "Customer"

Fields(1) = "Salesman"

Fields(2) = "Distributor ID"

Fields(3) = "Product ID"

Fields(4) = "Country"

Fields(5) = "Year"

'[ Initialize the container

ContainerObj = AxQlikOCX1.ActiveDocument.Sheets("Main").CreateContainer

ContProp = ContainerObj.GetProperties

ContProp.Frame.Name.v = "Selections"

ContProp.SingleObjectMode = 1

ContProp.SingleObjectStyle = 1

ContProp.ShowObjectTypeIcons = True

'[ actiate the sheet we want the container on (sheet name is case sensitive)

AxQlikOCX1.ActiveDocument.Sheets("Main").Activate()

'[ create the listbox, add it to the container, then close the listbox out (delete it)

For i = 0 To 5

'[ create the list box and set properties

ListboxObj = AxQlikOCX1.ActiveDocument.Sheets("Main").CreateListBox

LBID = ListboxObj.GetObjectId

LBProp = ListboxObj.GetProperties

LBProp.Def.Name = Fields(i)

LBProp.Def.Type = 1 '[ field

ListboxObj.SetProperties(LBProp)

'[ add the listbox to the container

ContProp.ContainedObjects.Add()

ContProp.ContainedObjects.Item(i).Def.ObjectId = LBID

ContProp.ContainedObjects.Item(i).Text.v = Fields(i)

'[ remove the newly created list box from the sheet but leave the copy in the container object

ListboxObj.Close()

Next

'[ set the container properties

ContainerObj.SetProperties(ContProp)

'[ Set container position and size

Dim rect As QlikView.IRect

rect = ContainerObj.GetRect

rect.Left = 2

rect.Top = 170

rect.Width = 274

rect.Height = 300

ContainerObj.SetRect(rect)

End Sub

Not applicable

Hi Jeff,

In slight variations of the above code, I'm trying to loop through the objects in a container and export them to Excel, but QV does not seem to like that.  Any suggestions on looping through the objects in a container and making this work?  I get an invalid FOR loop variable error.. Thanks in advance!!

For i = 1 To ActiveDocument.NoOfSheets -2

     Set MySheet = ActiveDocument.GetSheet(i)

     MySheet.Activate 

     contCharts=MySheet.GetSheetObjects

      For X =lbound(contCharts) to ubound(contCharts) 

      Set obj = ActiveDocument.GetSheetObject(contCharts(X).GetObjectId)

IF obj.GetObjectType = 36 then

      Set ContProp=obj.GetProperties

     Msgbox ContProp.ContainedObjects.Count   'it displays the count of objects correctly but it errors out in the next line below..

    For i = 0 to ((ContProp.ContainedObjects.Count) -1)

     ' export only the object types 10 to 16

     IF ContProp.ContainedObjects.Items(i).GetObjectType >= 10 AND ContProp.ContainedObjects.Items(i).GetObjectType =< 16 Then

          ContProp.ContainedObjects.Items(i).CopyValuesToClipboard true

          Msgbox ContProp.ContainedObjects.Items(i).GetCaption

'      End if

      Next

End if

Next

Not applicable

Where do I find the properties and methods of ContainedObjects member? I cant find any in the user manual, nor much information in the API guide.  Get the error that -

Object doesn't support this property or method: 'ContProp.ContainedObjects.Items'


prabhuappu
Creator II
Creator II
Author

Hi Jeff,

Thanks for the reply...

i used the below code to get the object IDs of the contained object.

          if (Sheets.SheetObjects(i.ToString()).GetObjectType() == 36)

                {

                    var Obj = (QlikView.Container)Doc.GetSheetObject(objectid);

                    var containerObjs = Obj.GetProperties().ContainedObjects;

                    for (int j = 0; j < containerObjs.Count; j++)

                    {

                        var ContainedObjId=containerObjs.Id_OBSOLETE;

                        var Def = containerObjs.Text;

                        string[] row = { ContainedObjId.Replace("Document\\", ""), Def.v, "Container " + objectid };

                        var listViewItem = new ListViewItem(row);

                        listView1.Items.Add(listViewItem);

                     }

                }

Regards

Prabhu Appu

prabhuappu
Creator II
Creator II
Author

Hi Nithya,

When copy the values to clipboard of contained objects, you need to activate the object.

but i couldn't see any function to activate the container object. So what i did is, i have created a copy of the object in a new sheet and then copied the values to clipboard (and don't forget to delete the newly created object before saving the application). Please find the below code for creating a copy of that object,

if (objecttype.Contains("Container"))

                {

                    QlikView.SheetObject QlikObject = (QlikView.SheetObject)Obj;

                    QlikView.Document QlikDoc = (QlikView.Document)Doc;

                    createobject(QlikDoc, QlikObject);

                  

                    //Clipboard.Clear();

                }

QlikView.Graph ObjectType14 = (QlikView.Graph)obj;

                    ObjectType14.WriteXmlPropertiesFile("Filename" + obj.GetObjectId().Replace("\\","") + ".xml");

doc.CreateSheet().CreateObjectFromXmlPropertiesFile(filename);

before copying the value or image to clipboard you need to activate that sheet and object,

if (objecttype.Contains("Container"))

                {

                    var ContainerObj = Doc.GetSheetObject(listView1.SelectedItems[0].SubItems[2].Text.Replace("Container\\",""));

                    ContainerObj.GetSheet().Activate();

                    ContainerObj.Activate();

                    ContainerObj.CopyTableToClipboard(true);

                }

                else

                {

                    Obj.Activate();

                    var docalias = (QlikView.Document)Doc;

                    docalias.GetSheetObject(objectid).CopyTableToClipboard(true);

                }

Regards,

Prabhu Appu