Quantcast
Channel: Active questions tagged listview - Stack Overflow
Viewing all articles
Browse latest Browse all 611

Issue with Data Display in ListView and Image Addition in LabWindows CVI 2015

$
0
0

I am currently facing an issue with displaying data in a ListView control in my LabWindows CVI 2015 project. The ListView remains empty, and I am receiving the following error message when attempting to add an image to the ImageList:

Error adding the image to the ImageList.

Despite following the standard procedure for adding data and configuring the ListView, the items do not appear as expected. Below is my code:

#include "mscomctl.h"#include <userint.h>#include <cviauto.h>#include <ansi_c.h>#include "Interface.h"// Global variable declarationsCAObjHandle listViewHandle = 0;CAObjHandle imageListHandle = 0; CAObjHandle listItems = 0;CAObjHandle listItem = 0;VARIANT imagePathVariant;VARIANT itemText;VARIANT itemIndex;VARIANT imageVariant;VARIANT imageVariant1; VARIANT imageVariant2; MSControlsObj_IImage imageObj;  // Declaration to store the image object// Image pathconst char *imagePath = "C:\\Users\\X425\\Desktop\\test\\image1.jpg";int main(int argc, char *argv[]) {    int panelHandle = LoadPanel(0, "Interface.uir", PANEL);    if (panelHandle < 0) {        printf("Error: Unable to load the panel.\n");        return -1;    }    // Get the ActiveX control handle for the ListView    int status = GetObjHandleFromActiveXCtrl(panelHandle, PANEL_LISTVIEW, &listViewHandle);    if (status < 0) {        printf("Error: Unable to get the ActiveX handle for the ListView.\n");        DiscardPanel(panelHandle);        return -1;    }    // Set the ListView to icon view mode    MSControls_SetIListViewProperty(listViewHandle, NULL, MSControls_IListViewView, CAVT_LONG, MSControlsConst_lvwIcon);    // Create an ImageList    status = GetObjHandleFromActiveXCtrl(panelHandle, PANEL_IMAGELIST, &imageListHandle);    if (status < 0) {        printf("Error: Unable to get the ActiveX handle for the ImageList.\n");        DiscardPanel(panelHandle);        return -1;    }    // Ensure the ImageList is valid    if (imageListHandle == 0) {        printf("Error: The ImageList is not valid.\n");        DiscardPanel(panelHandle);        return -1;    }    // Add the image to the ImageList    CA_VariantSetInt(&imageVariant1, 1);  // index (should be an integer)    CA_VariantSetInt(&imageVariant2, 0);  // key (should be an integer)    // Encapsulate the image path in a VARIANT as a string    CA_VariantSetCString(&imagePathVariant, imagePath);    // Call MSControls_IImagesAdd    HRESULT hr = MSControls_IImagesAdd(imageListHandle, NULL, imageVariant1, imageVariant2, imagePathVariant, &imageObj);    if (FAILED(hr)) {        printf("Error adding the image to the ImageList. HRESULT: 0x%08X\n", hr);        DiscardPanel(panelHandle);        return -1;    }    // Check if the image was successfully added    printf("Image successfully added.\n");    // Associate the ImageList with the ListView    MSControls_SetIListViewProperty(listViewHandle, NULL, MSControls_IListViewIcons, CAVT_OBJHANDLE, imageListHandle);    // Encapsulate the image index in a VARIANT (indices start at 1)    CA_VariantSetInt(&imageVariant, 1);    // Add items with the image    MSControls_GetIListViewProperty(listViewHandle, NULL, MSControls_IListViewListItems, CAVT_OBJHANDLE, &listItems);    if (listItems) {        for (int i = 1; i <= 5; i++) {  // Example: 5 items            CA_VariantSetCString(&itemText, "Item");            CA_VariantSetInt(&itemIndex, i);            MSControls_IListItemsAdd(listItems, NULL, itemIndex, CA_DEFAULT_VAL, itemText, imageVariant, CA_DEFAULT_VAL, &listItem);        }    }    // Display the panel    DisplayPanel(panelHandle);    RunUserInterface();    // Clean up resources    DiscardPanel(panelHandle);    CA_DiscardObjHandle(listViewHandle);    CA_DiscardObjHandle(imageListHandle);    CA_DiscardObjHandle(listItems);    CA_DiscardObjHandle(listItem);    CA_VariantClear(&imagePathVariant);    CA_VariantClear(&itemText);    CA_VariantClear(&itemIndex);    CA_VariantClear(&imageVariant);    return 0;}

After running this code, I configure the ListView and try adding items, but the ListView remains empty.

I searched the web for documentation or a user manual on the Microsoft ListView 6.0 library to help resolve this issue but was unable to find any relevant resources.


Viewing all articles
Browse latest Browse all 611

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>