03-19-2012 01:15 PM
Hi I want to disply data in different columns and same row in listbox using InsertListItem() but it displays the data in different rows.....I am using escape sequence for creating columns....Also I want to display an integer which I have converted to string using sprintf() on the listbox with a word, eg 10Kg where 10 is stored in some variable and I have to add Kg, How to do it in a single InsertItemList() call...Thank you
Solved! Go to Solution.
03-20-2012 12:55 AM
A single InsertListItem creates a single row in the listbox. All formatting and escape codes for the whole line to be inserted in the listbox must go in a single label to be passed to the function.
Could you post here your code so that we can revise it?
03-20-2012 02:21 AM
Thank you so much.....here the part of my code
InsertListItem (panel,PANEL_LISTBOX , 0, "#\033p30lItem\033p100lPackage\033p170lRate\033p220lPrice", 0); //this fills the first row InsertListItem (panel,PANEL_LISTBOX , 1, j, 1); /*in the first column I have to display serail no which changes each time*/ InsertListItem (panel,PANEL_LISTBOX , 1,"\033p30lFlour", 1); //then I have to display a different item in each column in which some are variables like rate/price etc and some
03-20-2012 07:07 AM
I see: you need to create the entire row before adding it to the listbox:
sprintf (string, "&d\033p30l%s\033p100l%s\033p170l%d\033p220l%.2f", itemNo, itemName, itemPack, 123, 15.98); InsertListItem (panel, PANEL_LISTBOX , 0, string, 0);
03-20-2012 09:40 AM
Another option is to use a tree control, which can be configured to look like a list control. The tree control supports proper columns. Check out http://forums.ni.com/ni/board/message?board.id=180&message.id=13541#M13541 for more info.
03-21-2012 03:48 AM
char * itemName[]={"item1","item2","item3","item4","item5","item6"}; char * itemPack[]={"10Kg","20Kg","40Kg","80Kg"}; void display_list(int j,int item_index,int pack_index,int rate, int quantity,int price) { sprintf(string,"%d\033p30l%s\033p100l%s\033p170%d\033p220l%d\033p270l%d",j,itemName[item_index], itemPack[pack_index],rate,quantity,price); InsertListItem (panelHandle,PANEL_LISTBOX , -1, string,0); } //I am calling this function to display the data //The item and pack are selected and then I set their indexes //accordingly and then pass them to the above function to display //the rate and quantity is also passed to the function price = rate * quantity; display_list(i,item_index,pack_index,rate,quantity,price);
I am doing this but the problem is that it only displays the price in the last column of the list box and doesn't display the other things.......Please tell me what I am doing wrong in the above code...
03-21-2012 05:49 AM
I can only see a missing alignment code in this line: correct it and test again.
sprintf (string, "%d\033p30l%s\033p100l%s\033p170x%d\033p220l%d\033p270l%d", j, itemName[item_index],
itemPack[pack_index], rate, quantity, price);