I do not know, because I want to add a possibility to use arrow-keys and Enter to open the edit-window.
When the Lisbox is very large and I do not know the exactly name, so is it possile to use a part of the name und after that scroll with the arrow-keys until I have found what I am seraching for. Now just press Enter.

Btw, when I change this:

    listboxLager.events().key_char([&listboxLager](const arg_keyboard& arg) {   // Event Taste Enter
        if((arg.key == keyboard::enter) && (lastSelect.b != "")) bearbeiten();  // Wenn Enter bei selektierter Listbox --> ...
    });

to this:

    listboxLager.events().key_char([&listboxLager](const arg_keyboard& arg) {   // Event Taste Enter
debug.caption("lastSelect.b = " + lastSelect.b);
        if((arg.key == keyboard::enter) && (lastSelect.b != "")) bearbeiten();  // Wenn Enter bei selektierter Listbox --> ...
    });

...then I recieve this error:
error: 'debug' is not captured
note: the lambda has no capture-default

What is this?

Edit:
When I change [&listboxLager] to [&] it works.
Why?

I do not know, because I want to add a possibility to use arrow-keys and Enter to open the edit-window. When the Lisbox is very large and I do not know the exactly name, so is it possile to use a part of the name und after that scroll with the arrow-keys until I have found what I am seraching for. Now just press Enter. Btw, when I change this: ```` listboxLager.events().key_char([&listboxLager](const arg_keyboard& arg) { // Event Taste Enter if((arg.key == keyboard::enter) && (lastSelect.b != "")) bearbeiten(); // Wenn Enter bei selektierter Listbox --> ... }); ```` to this: ```` listboxLager.events().key_char([&listboxLager](const arg_keyboard& arg) { // Event Taste Enter debug.caption("lastSelect.b = " + lastSelect.b); if((arg.key == keyboard::enter) && (lastSelect.b != "")) bearbeiten(); // Wenn Enter bei selektierter Listbox --> ... }); ```` ...then I recieve this error: error: 'debug' is not captured note: the lambda has no capture-default What is this? Edit: When I change [&listboxLager] to [&] it works. Why?
edited Oct 11 '18 at 8:10 pm

I do not know, because I want to add a possibility to use arrow-keys and Enter to open the edit-window.
When the Lisbox is very large and I do not know the exactly name, so is it possile to use a part of the name und after that scroll with the arrow-keys until I have found what I am seraching for. Now just press Enter.

Using the mouse_down event handler I provided doesn't affect the ability to navigate with the keyboard, or the ability to add any feature that would help with that. There is an adjustment that needs to be made, though:

    listboxLager.events().selected([&listboxLager](const arg_listbox& arg) {
        if(arg.item.selected())
            lastSelect = {arg.item.text(0),arg.item.text(1),arg.item.text(2)};
        else if(listboxLager.selected().empty())
            lastSelect = {};
    });

That's necessary because the selected event is sent twice when changing the selection from one item to another. When doing that with the mouse, the event is first sent with the arg.item that was deselected, and then with the arg.item that was selected. But when using the arrow keys, the order is reversed (no idea why), so we need the line else if(listboxLager.selected().empty()) to avoid overwriting lastSelect.

If you use the mouse_down event handler I provided, along with the modified selected event handler above, you no longer need to mess with lastSelectBefore, because double-clicking an item will never deselect it.

...then I recieve this error:
error: 'debug' is not captured
note: the lambda has no capture-default

All non-static variables declared in the surrounding scope must be captured in the capture clause of the lambda, if you want to use them inside the lambda. The capture clause [&listboxLager] only captures listboxLager, by reference. If you want to use debug as well, use this capture clause: [&listboxLager, &debug]

When I change [&listboxLager] to [&] it works.
Why?

Because [&] captures all variables used in the lambda by default (from the surrounding scope, by reference).

Lambda Expressions in C++

> I do not know, because I want to add a possibility to use arrow-keys and Enter to open the edit-window. When the Lisbox is very large and I do not know the exactly name, so is it possile to use a part of the name und after that scroll with the arrow-keys until I have found what I am seraching for. Now just press Enter. Using the `mouse_down` event handler I provided doesn't affect the ability to navigate with the keyboard, or the ability to add any feature that would help with that. There is an adjustment that needs to be made, though: ```` listboxLager.events().selected([&listboxLager](const arg_listbox& arg) { if(arg.item.selected()) lastSelect = {arg.item.text(0),arg.item.text(1),arg.item.text(2)}; else if(listboxLager.selected().empty()) lastSelect = {}; }); ```` That's necessary because the `selected` event is sent twice when changing the selection from one item to another. When doing that with the mouse, the event is first sent with the `arg.item` that was deselected, and then with the `arg.item` that was selected. But when using the arrow keys, the order is reversed (no idea why), so we need the line `else if(listboxLager.selected().empty())` to avoid overwriting `lastSelect`. If you use the `mouse_down` event handler I provided, along with the modified `selected` event handler above, you no longer need to mess with `lastSelectBefore`, because double-clicking an item will never deselect it. >...then I recieve this error: error: 'debug' is not captured note: the lambda has no capture-default All non-static variables declared in the surrounding scope must be captured in the capture clause of the lambda, if you want to use them inside the lambda. The capture clause `[&listboxLager]` only captures `listboxLager`, by reference. If you want to use `debug` as well, use this capture clause: `[&listboxLager, &debug]` >When I change [&listboxLager] to [&] it works. Why? Because `[&]` captures all variables used in the lambda by default (from the surrounding scope, by reference). [Lambda Expressions in C++](https://docs.microsoft.com/en-us/cpp/cpp/lambda-expressions-in-cpp?view=vs-2017)
edited Oct 12 '18 at 12:49 am

Thank you, the solution with mouse_down works great.
There is a litte problem.
...ok, it´s not really a problem smile ...
With this solution it is not possible to deselect a row.
But that is ok, the function is fully functional.

And thank you for the explanation about lambda. Now I have understood it smile

Thank you, the solution with mouse_down works great. There is a litte problem. ...ok, it´s not really a problem :D ... With this solution it is not possible to deselect a row. But that is ok, the function is fully functional. And thank you for the explanation about lambda. Now I have understood it :)
edited Oct 12 '18 at 4:13 pm

Hello again :-)
I was out of time, but now I want to finish my little program.

Now I have another problem:
I have written a form that allows users to enter data themselves.
It would be nice if the line in the list box is selected after it has been inserted by the form.
Is this possible?

I think at something like:
listbox.select("test 5" , "something" , "24"smile;

I have to search for the matching line and then select it.

Hello again :-) I was out of time, but now I want to finish my little program. Now I have another problem: I have written a form that allows users to enter data themselves. It would be nice if the line in the list box is selected after it has been inserted by the form. Is this possible? I think at something like: listbox.select("test 5" , "something" , "24"); I have to search for the matching line and then select it.

I think at something like:
listbox.select("test 5" , "something" , "24"smile;

I have to search for the matching line and then select it.

You don't have to search for the line, you can access the last item in the category and select it:

list_box.at(0).back().select(true, false);

Also, if the last argument of item_proxy::select is true instead of false, the item is also scrolled into view if it's not already visible.

>I think at something like: listbox.select("test 5" , "something" , "24"smile; >I have to search for the matching line and then select it. You don't have to search for the line, you can access the last item in the category and select it: ```` list_box.at(0).back().select(true, false); ```` Also, if the last argument of `item_proxy::select` is `true` instead of `false`, the item is also scrolled into view if it's not already visible.

Thank you for this solution, but I cant take the last element.
After adding an entry, the list will sorted. I dont know the new position.

For example:

Listbox before adding a new entry:
Trump - Donald - USA
Merkel - Angela - Germany
Macron - Emmanuel - France

Now adding: Mattarella - Sergio - Italy

New Listbox after sorting:
Macron - Emmanuel - France
Mattarella - Sergio - Italy
Merkel - Angela - Germany
Trump - Donald - USA

I want select now the last entry:
Macron - Emmanuel - France
Mattarella - Sergio - Italy
Merkel - Angela - Germany
Trump - Donald - USA

I have to search for the position, maybe like this:
for (...; i++)
if ( (listbox.at(0).pos(i) == lastName) && (listbox.at(1).pos(i) == firstName) && ...
listbox.select(i);

Do you have any idea, how I can solve this problem?

Thank you for this solution, but I cant take the last element. After adding an entry, the list will sorted. I dont know the new position. For example: Listbox before adding a new entry: _Trump - Donald - USA Merkel - Angela - Germany Macron - Emmanuel - France_ Now adding: _Mattarella - Sergio - Italy_ New Listbox after sorting: _Macron - Emmanuel - France Mattarella - Sergio - Italy Merkel - Angela - Germany Trump - Donald - USA_ I want select now the last entry: _Macron - Emmanuel - France **Mattarella - Sergio - Italy** Merkel - Angela - Germany Trump - Donald - USA_ I have to search for the position, maybe like this: for (...; i++) if ( (listbox.at(0).pos(i) == lastName) && (listbox.at(1).pos(i) == firstName) && ... listbox.select(i); Do you have any idea, how I can solve this problem?

Thank you for this solution, but I cant take the last element.
After adding an entry, the list will sorted. I dont know the new position.

That's not a problem, cat_proxy::back returns the last item in the unsorted order (which is the last one that was added).

It is important to understand that a listbox category doesn't actually reorder its internal item container when the items are sorted. Instead, each category maintains an index of display positions, and it is this index that is sorted instead of the item container. When sorting is enabled, the listbox simply displays the items in the sorted order, while continuing to address them using their absolute (unsorted) positions assigned to them at creation.

This is done to improve performance (it would be inefficient to actually move container elements into new positions).

>Thank you for this solution, but I cant take the last element. After adding an entry, the list will sorted. I dont know the new position. That's not a problem, `cat_proxy::back` returns the last item in the unsorted order (which is the last one that was added). It is important to understand that a listbox category doesn't actually reorder its internal item container when the items are sorted. Instead, each category maintains an index of display positions, and it is this index that is sorted instead of the item container. When sorting is enabled, the listbox simply _displays_ the items in the sorted order, while continuing to address them using their absolute (unsorted) positions assigned to them at creation. This is done to improve performance (it would be inefficient to actually move container elements into new positions).
edited Oct 4 at 12:05 am

Thank you very much, it really works :-)

But there are two problems:

First: The Listbox is big. The line is selected, but I cant see the selected line, because it is not in the visible area.

Second: The line is marked when I add a new entry, but if I edit the entry it does'nt works (the last added entry is marked, instead the edited).

Thank you very much, it really works :-) But there are two problems: First: The Listbox is big. The line is selected, but I cant see the selected line, because it is not in the visible area. Second: The line is marked when I add a new entry, but if I edit the entry it does'nt works (the last added entry is marked, instead the edited).

First: The Listbox is big. The line is selected, but I cant see the selected line, because it is not in the visible area.

When selecting an item, you can also scroll it into view if it's not already visible. Just use true as the last argument when calling item_proxy::select:

list_box.at(0).back().select(true, true);

I am currently working on a new (and hopefully much improved) version of the nanapro.org documentation. Its a work in progress, but the listbox section is finished. Take a look at it if you want to improve your understanding of the listbox: https://errorflynn.github.io/nana-docs/#widget_listbox

Second: The line is marked when I add a new entry, but if I edit the entry it does'nt works (the last added entry is marked, instead the edited).

Your description is not very clear. Are you saying you can't select a line after modifying it? If you could post the relevant code fragment, I might be able to get it to work.

>First: The Listbox is big. The line is selected, but I cant see the selected line, because it is not in the visible area. When selecting an item, you can also scroll it into view if it's not already visible. Just use `true` as the last argument when calling `item_proxy::select`: ```` list_box.at(0).back().select(true, true); ```` I am currently working on a new (and hopefully much improved) version of the nanapro.org documentation. Its a work in progress, but the listbox section is finished. Take a look at it if you want to improve your understanding of the listbox: https://errorflynn.github.io/nana-docs/#widget_listbox >Second: The line is marked when I add a new entry, but if I edit the entry it does'nt works (the last added entry is marked, instead the edited). Your description is not very clear. Are you saying you can't select a line after modifying it? If you could post the relevant code fragment, I might be able to get it to work.

Sorry, my english is very bad, so I have problems to descript my problem.
Another try..

I have build two forms. One of them creates a new entry. The problem with the select of the new entry and move them into the visible area is solved by you, many thanks.

The other form edits an entry. After edit the entry, the last "created" entry is selected in the listbox, instead the edited.

Example:

Create a new entry: banana - yellow - sweet
After that edit an existig entry: lemon - yellow - sour

Now should the line "lemon - yellow - sour" be selected, but instead the line "banana - yellow - sweet" is selected, because the data are stored in a file and new items are at the end of the file, so this are pushed into the listbox at least. The edited line has the same position in the file like before and will pushed to the listbox earlier.

Do you understand my problem?

Form edits or create an entry - saved in a file - listox will rebuild with data from the file.
To select an edited entry, i have to search for the position in the listbox and select this position.

Thank you very much for the great documetation. I have read onle the begin yet, but I´ve learnd a much already. Now I know the difference between colum_at() and at() ...and much more. The documentation is great and easy to understand. Thank you yery much !!!

Sorry, my english is very bad, so I have problems to descript my problem. Another try.. I have build two forms. One of them creates a new entry. The problem with the select of the new entry and move them into the visible area is solved by you, many thanks. The other form edits an entry. After edit the entry, the last "created" entry is selected in the listbox, instead the edited. Example: Create a new entry: banana - yellow - sweet After that edit an existig entry: lemon - yellow - sour Now should the line "lemon - yellow - sour" be selected, but instead the line "banana - yellow - sweet" is selected, because the data are stored in a file and new items are at the end of the file, so this are pushed into the listbox at least. The edited line has the same position in the file like before and will pushed to the listbox earlier. Do you understand my problem? Form edits or create an entry - saved in a file - listox will rebuild with data from the file. To select an edited entry, i have to search for the position in the listbox and select this position. Thank you very much for the great documetation. I have read onle the begin yet, but I´ve learnd a much already. Now I know the difference between colum_at() and at() ...and much more. The documentation is great and easy to understand. Thank you yery much !!!

Another question.

The selected line, selected by:

list_box.at(0).back().select(true, true);

is at the least position in the visible area. Here is a screenshot.
5d987f14bd4eb.png

I have solved it on this way (not nice, but works):

        p_listboxLager->at(0).back().select(true,true);
        p_listboxLager->move_select(0);
        p_listboxLager->move_select(0);
        p_listboxLager->move_select(0);
        p_listboxLager->at(0).back().select(true,true);

After add a new entry it looks so:
5d9880c76d237.png

Do you have a better solution?

Another question. The selected line, selected by: ```` list_box.at(0).back().select(true, true); ```` is at the least position in the visible area. Here is a screenshot. ![5d987f14bd4eb.png](serve/attachment&path=5d987f14bd4eb.png) I have solved it on this way (not nice, but works): ```` p_listboxLager->at(0).back().select(true,true); p_listboxLager->move_select(0); p_listboxLager->move_select(0); p_listboxLager->move_select(0); p_listboxLager->at(0).back().select(true,true); ```` After add a new entry it looks so: ![5d9880c76d237.png](serve/attachment&path=5d9880c76d237.png) Do you have a better solution?
edited Oct 5 at 12:43 pm

I can search for the position in the Listbox by this:

int index = 0;
for(vector<iniInhalt>::const_iterator i = ini.begin(); i!=ini.end(); ++i) {
    if(ini[index].b == textboxNeuB.caption() && ini[index].f == textboxNeuF.caption()) {
        pos = index;
        break;
    }
    index++;
}

...but how can I select the position in the listbox?

I can search for the position in the Listbox by this: ```` int index = 0; for(vector<iniInhalt>::const_iterator i = ini.begin(); i!=ini.end(); ++i) { if(ini[index].b == textboxNeuB.caption() && ini[index].f == textboxNeuF.caption()) { pos = index; break; } index++; } ```` ...but how can I select the position in the listbox?

I tried something, but unfortunately without success.

p_listboxLager->at(0).select(pos);

that also marks the last entry, instead the position.

I tried something, but unfortunately without success. ```` p_listboxLager->at(0).select(pos); ```` that also marks the last entry, instead the position.

I tried something, but unfortunately without success.

p_listboxLager->at(0).select(pos);

that also marks the last entry, instead the position.

cat_proxy::select selects the entire category. What you need is item_proxy::select to select the desired item, which you access with cat_proxy::at. The line should look like this:

p_listboxLager->at(0).at(pos).select(true, true);

p_listboxLager->at(0) returns a cat_proxy iterator to the default category (0), on which you call at(pos) which returns an item_proxy iterator to the desired item, on which you call select(true, true) to select the item and scroll it into view.

Another question.

The selected line, selected by:

list_box.at(0).back().select(true, true);

is at the least position in the visible area.

Unfortunately, there is no better solution than the one with move_select that you're using. Using a vertical alignment for the selected item when it's scrolled into view deserves to be a new feature. I could add it myself, but I'm not sure if Jinhao accepts new features.

The documentation is great and easy to understand. Thank you yery much !!!

Glad to hear it!

>I tried something, but unfortunately without success. ```` p_listboxLager->at(0).select(pos); ```` >that also marks the last entry, instead the position. [cat_proxy::select](https://errorflynn.github.io/nana-docs/#cat_proxy::select) selects the entire category. What you need is [item_proxy::select](https://errorflynn.github.io/nana-docs/#item_proxy::select) to select the desired item, which you access with [cat_proxy::at](https://errorflynn.github.io/nana-docs/#cat_proxy::at). The line should look like this: ```` p_listboxLager->at(0).at(pos).select(true, true); ```` `p_listboxLager->at(0)` returns a `cat_proxy` iterator to the default category (0), on which you call `at(pos)` which returns an `item_proxy` iterator to the desired item, on which you call `select(true, true)` to select the item and scroll it into view. >Another question. >The selected line, selected by: ```` list_box.at(0).back().select(true, true); ```` is at the least position in the visible area. Unfortunately, there is no better solution than the one with `move_select` that you're using. Using a vertical alignment for the selected item when it's scrolled into view deserves to be a new feature. I could add it myself, but I'm not sure if Jinhao accepts new features. >The documentation is great and easy to understand. Thank you yery much !!! Glad to hear it!
edited Oct 5 at 6:48 pm

Thank you again :-)
It works perfect with

p_listboxLager->at(0).at(pos).select(true, true);

And also many thanks for the good explanation, that helps me very much to understand the whole thing.

Thank you again :-) It works perfect with ```` p_listboxLager->at(0).at(pos).select(true, true); ```` And also many thanks for the good explanation, that helps me very much to understand the whole thing.

Sorry, but I have another question smile

When I enter text in a form field:

textboxNeuB.caption(lastSelect.b);

then the cursor is at the beginning of the text. I would like the cursor to be at the end of the text, so that you can extend the text directly when writing. The field already has the focus, but how do I get the cursor to the end?

Sorry, but I have another question (:| When I enter text in a form field: ```` textboxNeuB.caption(lastSelect.b); ```` then the cursor is at the beginning of the text. I would like the cursor to be at the end of the text, so that you can extend the text directly when writing. The field already has the focus, but how do I get the cursor to the end?

You must call textbox& textbox::caret_pos(const upoint& pos). The upoint data type of the pos parameter is a structure with the data members unsigned x and unsigned y. Those represent the coordinates in the text box where you want to move the caret (x is the character offset within a line, and y is the the line number, both starting at 0). If you use maximum values for x and y, the caret will be moved to the end of the text.

const unsigned max_uint = static_cast<unsigned>(-1);
textboxNeuB.caret_pos({max_uint, max_uint});
You must call `textbox& textbox::caret_pos(const upoint& pos)`. The `upoint` data type of the `pos` parameter is a structure with the data members `unsigned x` and `unsigned y`. Those represent the coordinates in the text box where you want to move the caret (`x` is the character offset within a line, and `y` is the the line number, both starting at 0). If you use maximum values for `x` and `y`, the caret will be moved to the end of the text. ```` const unsigned max_uint = static_cast<unsigned>(-1); textboxNeuB.caret_pos({max_uint, max_uint}); ````

Thanks again!
It works perfectly, and thanks to your good description I understood it too.

Would it have any disadvantages if I shortened it that way? :

textboxNeuB.caret_pos({lastSelect.b.length(), 0});
Thanks again! It works perfectly, and thanks to your good description I understood it too. Would it have any disadvantages if I shortened it that way? : ```` textboxNeuB.caret_pos({lastSelect.b.length(), 0}); ````

Would it have any disadvantages if I shortened it that way? :

textboxNeuB.caret_pos({lastSelect.b.length(), 0});

No, there are no disadvantages to doing that. I only used max values because I didn't know the content of the textbox. If you know for sure that there's only one line, you can do it your way.

>Would it have any disadvantages if I shortened it that way? : ```` textboxNeuB.caret_pos({lastSelect.b.length(), 0}); ```` No, there are no disadvantages to doing that. I only used max values because I didn't know the content of the textbox. If you know for sure that there's only one line, you can do it your way.
12
214
views
38
replies
4
followers
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft