ZNorQ 0 Posted October 17, 2007 I know how to add content (lines/records) to a combo control, but I want to change the content of a record and I just can't find out how... Example; COMBOBOX; MY FIRST LINE MY SECOND LINE MY THIRD LINE Lets say I want to change the second item to MY SECOND AND BEST LINE How do I do that? Share this post Link to post Share on other sites
benreeper 0 Posted October 17, 2007 The only way that I've been able to do it is thru re-filling the list/combo box. --Ben Share this post Link to post Share on other sites
TheJay 0 Posted October 17, 2007 I do the same thing as Ben but only delete the changing entry and readd it with the updated text. Of course, if you need stuff in a certain order this won't work to well. For that I liberally use lbSort or lbSortbyValue. Share this post Link to post Share on other sites
UNN 0 Posted October 18, 2007 Quote[/b] ]I know how to add content (lines/records) to a combo control, but I want to change the content of a record and I just can't find out how... Not sure about the Combox, but it's possible with a Listbox. AFAIK there isn’t much difference between the two? Quote[/b] ]Lets say I want to change the second item to  MY SECOND AND BEST LINE You could loop through the content of the Combobox incrementing a counter. Once you found the entry for MY SECOND LINE, you could use the value in the counter as an index. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">For [{_x=0},{_x<(lbSize _MyComboBox)},{_x=_x+1}] Do     {     If ((_MyComboBox lbText _x)=="MY SECOND LINE") ExitWith         {         _MyComboBox lbDelete _x;         _NewItem=_MyComboBox lbAdd "MY SECOND AND BEST LINE";         };     }; The combo box has to be sorted otherwise it will just add the new item at the end. But if you don't want to sort by text you can add a suitable value with lbSetValue and sort using that. You can also do the search using lbValue, but you will have to organise that yourself before adding items to a list or combo. It works for the ListBox so I'm assuming it will work for a ComboBox to. Share this post Link to post Share on other sites
shinRaiden 0 Posted October 18, 2007 This is why you need to be a programmer to do practical scripting. I've always thought tree and list type objects were 'cool', but it was always frustrating to figure out how to manage them. I expected to manage the content via the control, and always got frustrated trying to figure out how to manipulate the data. Finally someone a lot wiser than me suggested, "Don't use the control for your content handlers, put that all in the backend, and have the control be the interface to your logic, and the logic to the data." For example, this would mean putting index values as the data into your control, rather than putting the data itself. Then, you use the parameters from the control to figure out what to manipulate with your data sources. You logic then determines what the control should look like, rather than the control getting confused as to what to do with the data. Some controls allow you to modify or append the control's data, but in a worst-case scenario, you can still easily blank and reload the control, provided your backend logic is happy. Share this post Link to post Share on other sites
.kju 3245 Posted October 18, 2007 Good thought shinRaiden! This pattern is called model-view-controller pattern. Very recommended to use! Share this post Link to post Share on other sites
ZNorQ 0 Posted October 19, 2007 @All; Just an explanation of my real intentions with the combo; In my COOP missions, I want one of the players to be a radio operator. His/her radio will be the recipient of headquarters messages - messages that we receive during our mission that is triggered in certain situations. He/she will also be able to receive enemy radio communications, but wont be able to read them unless he/she has the right decryption key. The server generates these messages in a strict fasion - an array containing these elements; [ [iD, "ENCRYPTION KEY", Read?:Boolean, "Date", "Time", "To", "From", "Title", "Full message"] ] Basically, the "title" is the only field that is showen in the combo, but I also prefix the title with a ">> " to indicate that this haven't been read yet. And this is the only reason I want to change the text content. When the radio operator selects an unread line, the array will be updated with "TRUE" in position 3 (2 in array terms), and the ">> " will be removed from the line. Now, my solution so far is to lbClear the content and refill it - but I was hoping that this wouldn't be necessary. (And yes, it reselects the last selected item in the list.) My experience from windows API programming, this often causes "flickering" effects when you have many elements in that list - and I want to try avoiding that. If I understand shinRaiden correctly, his point is that I should use a main source (backend?) to update information - probably in my case the radio array list - and then represent that information by clearing and re-listing the relevant data. I think that is a good way to do it - and have tried to practice this a long time (in Win32 API programming). But - as I said, I'd want to try to have the lists be as "smooth" as possible and make sure the user don't see these relisting updates. If I had the following script functions in ArmA, I'd be a very happy man; lbSortByData lbChangeText (..or something like that) These would make the combo/list content handling alot easier. I hope the lbChangeText is obvious, but as for the lbSortByData - that would make it possible for me to add invisible text to each list element, and then sort by it without having to change the text content in the combo/list just to sort it correctly. Lets for example say that I want to sort by READ/NOT READ, DATE, TIME, FROM, I would go through the whole list using lbSetData "READ:BOOLEAN" + "DATE" + "TIME" + "FROM" (*1) on all lines, and then apply the lbSortByData. I've would have already used lbAddValue ID to make sure that the combo is referenced correctly back to the array. This way I wouldn't have to worry about having the combo and the array be sorted the same way. PS! I could ofcourse do this by using a temp array, sort that, and fill the combo based on it... For now I'll just update the array, lbClear the combo and relist the information. This is already my solution so far. Perhaps, though, we should (if you agree with me) propose the lbChangeText and lbSortByData to implemended in ArmA? Anyway, thanks to all of you for your valuable feedback. ZNorQ *1) I know the syntax is wrong, I just use this to illustrate my point. Share this post Link to post Share on other sites
UNN 0 Posted October 19, 2007 Quote[/b] ]sort by it without having to change the text content in the combo/list just to sort it correctly. You don't have to change the text to sort a listbox: lbSortByValue Share this post Link to post Share on other sites
ZNorQ 0 Posted October 19, 2007 Quote[/b] ]sort by it without having to change the text content in the combo/list just to sort it correctly. You don't have to change the text to sort a listbox: lbSortByValue Hehe, I know. I was making reference to the use of lbData which is (as I understand it) invisible text that you can use for certain purposes, I guess. Sorting by value is abit bothersome, because it's just a number (or am I incorrect?). Usually it is text strings, dates, or similar data that I want to sort by - not just a number. As far as I can see, there are 3 elements to a combo/list box element; A text, a value and some data. Text is the visible text in the listing, a value is an invisible number, and data is extra invisible text that you can apply. If possible, I would use value as a reference to the radio msg. array I mentioned earlier, while data would be a concentrated set of values (strings, booleans, numbers, etc.) that I used to sort the list by. This isn't possible, as there are no sort command for lbData. I guess this is abit off-topic, as we where initially talking about changing the text content, not sorting it... ZNorQ Share this post Link to post Share on other sites