Ecere SDK/eC Forums http://ecere.org/community/ Print view |
|
[Solved]How to iterate through ListBox http://ecere.org/community/viewtopic.php?f=5&t=191 |
Page 1 of 2 |
Author: | samsam598 [ Tue Sep 13, 2011 2:55 am ] |
Post subject: | [Solved]How to iterate through ListBox |
Hi, I want to pick every row of a given listBox but are not able to find the right method.Could you please figure me out? Code: Select all
|
Author: | jerome [ Tue Sep 13, 2011 10:38 am ] |
Post subject: | Re: How to iterate through ListBox |
Sam, Just like with child windows, you can use ListBox::firstRow and DataRow::next to iterate through the rows: Code: Select all
Code: Select all
|
Author: | samsam598 [ Wed Sep 14, 2011 4:43 am ] |
Post subject: | Re: [Solved]How to iterate through ListBox |
Cool. How to make use of ListBox and DataField to create a database grid?Or any other solution should be fine also.Please note I need the headers as well.Thanks. ----------------------------------------------------------------- ID |姓名 |出生日期 |喜好 | ----------------------------------------------------------------- 0001 | 王小早 |1987/06/26|打球、下棋、听音乐 | ----------------------------------------------------------------- |
Author: | jerome [ Wed Sep 14, 2011 10:35 am ] |
Post subject: | Re: [Solved]How to iterate through ListBox |
Sam, Here's sample code for a grid view ListBox. It uses 'ShortDate.ec' in sdk/extras, you need to add the file to the project. Code: Select all
You can also use EDA to plug in a database directly, e.g. with eda::Table::GUIListBoxAddFields and eda::Table::GUIListBoxAddRowsField. This will automatically add DataFields and DataRows to the ListBox. Regards, Jerome |
Author: | samsam598 [ Wed Sep 14, 2011 8:15 pm ] |
Post subject: | Re: [Solved]How to iterate through ListBox |
Thanks Jerome,that's great! After adding double-click event,noticed there is a sligth problem,when double click on the second row,the sort order of the both row changed.Don't know why. Code: Select all
Code: Select all
Code: Select all
|
Author: | jerome [ Wed Sep 14, 2011 8:53 pm ] |
Post subject: | Re: [Solved]How to iterate through ListBox |
Hi Sam, I noticed a couple of problems in your NotifyDoubleClick method. First, you're deleting 'name' which was obtained through 'DataRow::GetData'. The data belongs to the ListBox, so you should not delete that (it causes all kinds of problems when I ran your sample). Then you have a buffer overflow when using sprintf with IDstr, you're putting at least 6 characters (:,I,D,=,1,\0) in that buffer and you only reserved space for 3. I suggest you make it bigger, like 30. temp is a bit on the small size as well, if you have a bigger name, keep in mind most Chinese characters will take up 3 bytes each in UTF-8 encoding. Finally, since the ListBox has 'moveRows' set to true, when you click and drag a row it automatically drags it around. That's the behavior that you're seeing as changing the sort order, it's triggered after the NotifyDoubleClick finishes. To prevent this from happening, simply return 'false' from NotifyDoubleClick, and the ListBox will not continue processing the current mouse event. Of course you can also disable the moveRows functionality (it's normally not used in conjunction with 'sortable'). Here's your updated NotifyDoubleClick: Code: Select all
Jerome |
Author: | jerome [ Wed Sep 14, 2011 9:02 pm ] |
Post subject: | Re: [Solved]How to iterate through ListBox |
Sam, The following will build: Code: Select all
Cheers, Jerome |
Author: | samsam598 [ Wed Sep 14, 2011 9:33 pm ] |
Post subject: | Re: [Solved]How to iterate through ListBox |
Thank you Jerome,all fixed!! |
Author: | samsam598 [ Thu Sep 15, 2011 4:48 am ] |
Post subject: | Re: [Solved]How to iterate through ListBox |
One more question,sorry! If I wrote a separate function which will fill in the listBox with data and then pass the function to the form's constructor,the app will compile,but when runs,it will crash.So what makes this difference? Code: Select all
Code: Select all
Code: Select all
|
Author: | jerome [ Thu Sep 15, 2011 9:13 am ] |
Post subject: | Re: [Solved]How to iterate through ListBox |
Sam, It really doesn't make any difference. The problem must be somewhere else. Could you please paste the entire sample that crashes? EDIT: I've managed to reproduce it, and found that the problem is a char buffer (name[10], in this case) too small again. This works: Code: Select all
Jerome |
All times are UTC-05:00 | Page 1 of 2 |
Powered by phpBB® Forum Software © phpBB Limited |