04-01-2011 02:00 AM
Hi All,
I have a table control with one column. What function should I use to retrieve all the rows ? Do I need to iterate row by row and read each row or is it possible to do it in one function ?
Thanks,
Kanu
Solved! Go to Solution.
04-01-2011 02:12 AM - edited 04-01-2011 02:14 AM
Supposing vells in the column have all the same data type, you can retrieve the whole column with a single instruction:
GetTableCellRangeVals (panel, control, VAL_TABLE_COLUMN_RANGE (1), array, VAL_COLUMN_MAJOR);
The array passed must be large enough to retrieve all data. Alternatively, you may substitute the macro VAL_TABLE_COLUMN_RANGE with the appropriate MakeRect instruction.In case your table was dinamically built, you can obtain the nu,ìmber of rows using GetNumTableRows and dimension your array accordingly.
The above macro is defined in userint.h together with some other useful macros that can be used to access data in a table.
There are some precautions to take in case of string values or some cell type (ring, combo box, button...) that are described in the hell for the function.
04-05-2011 02:05 PM - edited 04-05-2011 02:09 PM
Hi Roberto,
Thanks for your answer. I appreciate it. I tried using what you suggested, I keep getting out of index error for GetTableCellRangeVals. I guess I am doing something wrong in MakeRect function. Any suggestions for that ?
Regards,
Kanu
04-05-2011 04:06 PM
The first thing that comes to my mind is that row/col indexes on a table are 1-based, differently from array indexes in C which are 0-based. Have you tried using VAL_TABLE_COLUMN_RANGE macro I suggested? You can see how this macro is defined in userint.h.
The second possibility is thgat the array you are using to retrieve data is too little: if you are allocating it dynamically, could there be some error in calculating its size? Can you try with a smaller area to test your function?
04-05-2011 04:56 PM
Thanks Roberto. VAL_TABLE_COLUMN_RANGE macro works fine. But I still have a doubt why is MakeRect not working. I gave the MakeRect function as MakeRect (1,1,iNumRows,1), where iNumRows are the total number of rows obtained from GetNumTableRows function.
Regards,
Kanu
04-05-2011 11:48 PM
As you can see in this page, VAL_TABLE_COLUMN_RANGE is defined as:
MakeRect (1, (c), 1, VAL_TO_EDGE)
that is, you must pass the number of rows in the last parameter of the Rect structure.
04-08-2011 07:29 PM
Hi All,
GetTableCellRangeVals worked fine for numeric data. But it gives error of array size of arrTest being too small for string type cells. My code is as follows:
int iNumRows = 0;
int iNumCols = 0;
char *arrTest = NULL ;
GetNumTableRows(gPanelHandle, pnlIPandDB_tblList, &iNumRows);
GetNumTableColumns(gPanelHandle, pnlIPandDB_tblList, &iNumCols);
arrTest = calloc (iNumRows * iNumCols, sizeof (char[500]));
GetTableCellRangeVals (gPanelHandle, pnlIPandDB_tblList, VAL_TABLE_COLUMN_RANGE (1), &arrTest, VAL_COLUMN_MAJOR);
I think I am missing something. I will appreciate if someone can help me on this.
Thanks,
Kanu
04-08-2011 08:12 PM
Never mind. Got it. I used char *arrTest[100] and used arrTest in place of array in GetTableCellRangeVals.
Regards,
Kanu