03-13-2018 01:20 PM
hi, everyone... i have problem to fill second column in a tree control... the cells are editables, but the first column is edited and i get error on second columns index???!!
my codes are as follow:
int CVICALLBACK startCB (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
double xn[100]={0.0}, sine[200];
double x[200]={0.0}, y[200]={0.0};
double amp=1.0, cycle=0.25;
int i,j,k=2;
char sx[100], sy[100];
switch (event)
{
case EVENT_COMMIT:
InsertTreeColumn (panelHandle, PANEL_TREE, 1, NULL);
SetTreeColumnAttribute (panelHandle, PANEL_TREE, 0, ATTR_LABEL_TEXT, "X Value");
SetTreeColumnAttribute (panelHandle, PANEL_TREE, VAL_ALL_OBJECTS, ATTR_COLUMN_VISIBLE, 1);
SetTreeColumnAttribute (panelHandle, PANEL_TREE, 1, ATTR_LABEL_TEXT, "Y Value");
SetTreeColumnAttribute (panelHandle, PANEL_TREE, VAL_ALL_OBJECTS, ATTR_COLUMN_VISIBLE, 1);
for(i=0;i<100;++i)
sine[i]=amp*sin(sqrt(2*PI*i*cycle/100));
i=2;
xn[i-2]=0.0;
xn[i-1]=amp*sin(sqrt(2*PI*cycle/100+xn[i-2]));
while((xn[i-1]-xn[i-2]) >0.00001){
xn[i]=amp*sin(sqrt(xn[i-1]));
sprintf(sx,"%.5f",xn[i-1]);
sprintf(sy,"%.5f",xn[i]);
++i;
SetTreeCellAttribute (panelHandle, PANEL_TREE, VAL_ALL_OBJECTS, 0, ATTR_CELL_TYPE, VAL_CELL_STRING);
InsertTreeItem (panelHandle, PANEL_TREE, VAL_SIBLING, 0, VAL_LAST, sx, NULL, NULL, xn[i-1]);
SetTreeCellAttribute (panelHandle, PANEL_TREE, VAL_ALL_OBJECTS, 1, ATTR_CELL_TYPE, VAL_CELL_STRING);
InsertTreeItem (panelHandle, PANEL_TREE, VAL_SIBLING, 1, VAL_LAST, sy, NULL, NULL, xn[i]);
}
x[0]=0.02; x[1]=0.02; y[0]=0.02; y[1]=sine[2];
for(j=2;j<100;j+=2){
x[k]=y[j-1];
y[k]=y[j-1];
x[k+1]=y[j-1];
y[k+1]=amp*sin(sqrt(2*PI*y[j]*cycle));
k+=2;
}
PlotLine (panelHandle, PANEL_GRAPH, 0, 0, 1, 1, VAL_GREEN);
PlotWaveform (panelHandle, PANEL_GRAPH, sine, 100, VAL_DOUBLE, 1.0, 0.0, 0.0, 0.01, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
PlotXY (panelHandle, PANEL_GRAPH, x, y, i-1, VAL_DOUBLE, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_DASH, 1, VAL_YELLOW);
break;
case EVENT_ZOOM:
SetCtrlAttribute (panelHandle, PANEL_GRAPH, ATTR_ENABLE_ZOOM_AND_PAN, 1);
SetCtrlAttribute (panelHandle, PANEL_GRAPH, ATTR_ZOOM_STYLE, VAL_ZOOM_TO_RECT);
break;
}
return 0;
}
it doesnt like the 1, as second columns index in the following code:
InsertTreeItem (panelHandle, PANEL_TREE, VAL_SIBLING, 1, VAL_LAST, sy, NULL, NULL, xn[i]);
why i cannot find the reason... can anybody help me out? thanks snd kind regards
Solved! Go to Solution.
03-14-2018 02:52 AM
That's because writing to columns in a tree must be done using SetTreeCellAttribute. Specifically, InsertTreeItem creates an itema in the tree, writing in column 0 and returning the item index. SetTreeCellAttribute can write to other columns of the same item by passing the item index and the column index to it.
See CVI example TreeBusDigitalGraph in <CVISamplesFolder\userint folder for an example of using these commands: AddLine is the function to look at.
03-14-2018 10:16 AM
roberto and thanks for your reply... i have replaced with:
SetTreeCellAttribute (panelHandle, PANEL_TREE, VAL_ALL_OBJECTS, 0, ATTR_TOOLTIP_TEXT, sx);
SetTreeCellAttribute (panelHandle, PANEL_TREE, VAL_ALL_OBJECTS, 1, ATTR_TOOLTIP_TEXT, sy);
but the tree is empty... i added och replaced with:
lsx=strlen(sx);
lsy=strlen(sy);
GetTreeCellAttribute (panelHandle, PANEL_TREE, VAL_DFLT_FOR_NEW_OBJECTS, 0, ATTR_TOOLTIP_TEXT_LENGTH, lsx);
SetTreeCellAttribute (panelHandle, PANEL_TREE, VAL_ALL_OBJECTS, 0, ATTR_TOOLTIP_TEXT, sx);
GetTreeCellAttribute (panelHandle, PANEL_TREE, VAL_DFLT_FOR_NEW_OBJECTS, 1, ATTR_TOOLTIP_TEXT_LENGTH, lsy);
SetTreeCellAttribute (panelHandle, PANEL_TREE, VAL_ALL_OBJECTS, 1, ATTR_TOOLTIP_TEXT, sy);
i got ERROR:
FATAL RUN-TIME ERROR: thread id 11968: The program has caused a 'General Protection' fault at 0x6868A32C.
actually, i dont know what kind of attribute i should choose, i choosed, ATTR_TOOLTIP_TEXT or ATTR_LABEL_TEXT, therefore it needed GetTreeCellAttribute...
i appreciate your help... thanks... kind regards
03-14-2018 11:55 AM
Is there a reason to programmatically customize the tree instead of designing it in the UIR editor? I had no problem in populating trees in my programs, but I always can design them before the program run. Nevertheless, the example I pointed you to before programmatically customizes the tree at program start, so you can use it as a reference source.
Regarding the tooltip, this is the text that is dynamically displayed when you hover thee mouse over the control, not a static text always visible.
03-14-2018 03:10 PM
Hello roberto... thanks for your reply... i have also designed the tree before program run, but the same result... i cannot find proper attribute to put my values in each columns, using SetTreeCellAttribute...
thanks for your reply... kind regards
03-15-2018 02:42 AM
Can you post a small sample working project of your actual situation? It's hard for us to imagine your situation and try guessing what's going on.
03-18-2018 10:20 AM
dear roberto, hello and sorry my late reply, were quite busy... i attach my whole project to you...
i have made comment, making column inside a tree programatically, even those codes, i got error for index range...
but i put other codes and i get ERROR: general protection...???!!!
when you run he program, click on start... you can zoom in the graph and thereafter restore it by the key... thanks for your help... have a good day... kind regards, venus
03-18-2018 02:01 PM
I corrected the code that writes to the tree, but it seems to me that you haven't looked at the sample code I pointed you to before.
Please read this discussion again and pay attention to this sentence:
(...) InsertTreeItem creates an item in the tree, writing in column 0 and returning the item index. SetTreeCellAttribute can write to other columns of the same item by passing the item index and the column index to it.
It dates 4 days back...
03-18-2018 02:38 PM
hello roberto and thansk for your reply... i have proved your recommendation too, but it doesnt write any in Y_Value Column??!!
can you send me the corrected .c file? thanks... kind regards, venus
03-19-2018 02:53 AM
Here it is
(I forgot to put the attachment yesterday)