Antony R.
2016-04-25T23:51:53Z
Retrieve Combo box associated value.
Hello…
I have an igrid with multiple igCellTextCombo, combo boxes.
Every combo box is populated with a sub-query of rows of a table.
It could be the same or different sub-query for every combo.
When adding combobox, sItemText is set to the searchable by user description while vItemValue is set to the ID of the record.
I need to show the description to the user but store the ID value.
So I need to know the index of the selected value of the combo box, to retrieve the corresponded ItemValue(), value and store it.
But there is no property that returns /set this index!
The only index that is returned is through ValueIndex() property that expects as parameter the value I need to find…
Looping through all items and searching for the specific text is an obvious solution but creates a lag while editing because the listcount could be over 1000 items.
So a listindex get/set property would be very helpful.
Get would return the currently selected index of the combo box. (this should return zero for newly inserted items)
Set would select the specific item.

Except if I am missing something here...
Igor/10Tec
2016-04-26T07:25:34Z
You need to use the cells of the igCellCombo type. They are not editable as text, but the incremental search is supported. Cells of these type store combo box item values in their cell values, so your task becomes trivial: you just read the CellValue property for the required cell.
Antony R.
2016-04-26T10:53:19Z
Originally Posted by: Igor/10Tec 

You need to use the cells of the igCellCombo type. They are not editable as text, but the incremental search is supported. Cells of these type store combo box item values in their cell values, so your task becomes trivial: you just read the CellValue property for the required cell.



Yes but this way you loose the functionality of adding new, unlisted values, to the combo box.


Igor/10Tec
2016-04-26T11:34:47Z
I can think about a workaround or tool to retrieve the internal index of the combo item. But can you tell me the logic of your app related to these cells? I think there should be a special processing of new entered strings that are not on the list: you need to add them to the db from code, retrieve their IDs, add them to the combo list attached to the cell, etc.
Antony R.
2016-04-26T14:48:39Z
Originally Posted by: Igor/10Tec 

I can think about a workaround or tool to retrieve the internal index of the combo item. But can you tell me the logic of your app related to these cells? I think there should be a special processing of new entered strings that are not on the list: you need to add them to the db from code, retrieve their IDs, add them to the combo list attached to the cell, etc.



I'm an Ms Access developer for years now.
Maybe my problem is how much easy is in Access to handle combo boxes. 🙂
In the other hand Igrid can to much more than Access continues forms. That is why I am trying to replace some of them to add functionality and avoid the much hated flickering.
In Access, Combo boxes combine both worlds of your two kinds of combo boxes. (igCellCombo and igCellTextCombo).
There is a “LimitToList” property that defines if the user can or cannot type text other than the listed values.
There is also a “NotInList” event that is triggered every time the user types something out of the listed values.
If, in the event code, you add the value to the database (and tell Access that you did it) , Access requeries the combo box list and places the new value in the correct order. (e.g. alphabetical order).
In both cases, there is a bound column to the combo box that can be different from the displayed column. (as in igCellCombo).
Let’s have an example :

Let’s say that you have a table with towns and their unique ids and you must be able to add new ones.

To accomplish this in Igrid one must use igCellTextCombo and…:
• Open Recordset as above and populate the values one by one through looping in it. ( a “FillFromRS” procedure for comboboxes would be nice and faster (I suppose))
• When a user selects a listed town, to store the ID in the database, developer must do a binary recursive search in Combo Box items (or loop) to find the corresponding Index of the displayed text, so that you can retrieve the ItemValue and store it.
• When user enters a new town, developer must do again a binary recursive search in Combo Box items to find if the town is listed. If not, new Town must be added to the database and repopulate the combo box to include the new value or must find by code the proper index to insert it.

To accomplish this in Igrid if listindex property was existed:
• Open Recordset as above and populate the values one by one through looping in it.
• When user selects a listed town, store ItemValue(ListIndex) to the database
• When user enters a new town, (listindex should be zero or -1 if zerobased), add town to the database and repopulate the combo box to include the new value or find by code the proper index to insert it.
This is a much more clean approach, which eliminates errors in the process and most of all is very mach faster if we consider comboboxes with many items.

That is, again, if I'm not missing something...
Igor/10Tec
2016-04-28T08:09:28Z
The problem with the igCellTextCombo cells is that their values are not linked to the combo list item values as the user can enter any arbitrary text. iGrid and its combo lists are not bound to data sources. If they were so, perhaps, we could even implement some smart logic to add new missing cell texts automatically to combo lists.

Some time ago we implemented the ability to retrieve the index of the selected combo list item for the last user selection in the case of the igCellCombo cells:

http://10tec.com/forum/p...th-style-igCellTextCombo 

This helper tool can be used through the DevDbg call with the parameter 3 like this:

Dim lListIndex As Long
iGrid1.DevDbg 3, lListIndex

It also works for combo item selection in the case of the igCellTextCombo cells. Perhaps, it will help you somehow.

Let me think whether this trick can be used for text editing for this type of cells.
Igor/10Tec
2016-04-28T09:59:29Z
I have implemented this in a new interim build of iGrid and sent the link to download it to your mailbox.

One more thought about the functionality you need to implement:

Citação:

• When a user selects a listed town, to store the ID in the database, developer must do a binary recursive search in Combo Box items (or loop) to find the corresponding Index of the displayed text, so that you can retrieve the ItemValue and store it.
• When user enters a new town, developer must do again a binary recursive search in Combo Box items to find if the town is listed. If not, new Town must be added to the database and repopulate the combo box to include the new value or must find by code the proper index to insert it.



You may think about finding these values directly in the recordset you used to populate the combo list. Perhaps, the recordset object can provide you with its own methods to find what you need.
Antony R.
2016-04-28T17:33:34Z
Originally Posted by: Igor/10Tec 

The problem with the igCellTextCombo cells is that their values are not linked to the combo list item values as the user can enter any arbitrary text. iGrid and its combo lists are not bound to data sources. If they were so, perhaps, we could even implement some smart logic to add new missing cell texts automatically to combo lists.

Some time ago we implemented the ability to retrieve the index of the selected combo list item for the last user selection in the case of the igCellCombo cells:

http://10tec.com/forum/p...th-style-igCellTextCombo 

This helper tool can be used through the DevDbg call with the parameter 3 like this:

Dim lListIndex As Long
iGrid1.DevDbg 3, lListIndex

It also works for combo item selection in the case of the igCellTextCombo cells. Perhaps, it will help you somehow.

Let me think whether this trick can be used for text editing for this type of cells.



It works just fine! Thanx!!!

Code Example :

Private Sub iGrid0_BeforeCommitEdit(ByVal lRow As Long, ByVal lCol As Long, eResult As Long, ByVal sNewText As String, vNewValue As Variant, ByVal lConvErr As Long, ByVal bCanProceedEditing As Boolean)
    Dim ListIndex As Long
    If Grd.CellType(lRow, lCol) = igCellTextCombo Then
        Grd.DevDbg 3, ListIndex
        If ListIndex = -1 Then
            If Not AddNewValueToCB(lRow, vNewValue) Then
                eResult = igEditResProceed
            End If
        End If
    End If
End Sub

Private Sub iGrid0_AfterCommitEdit(ByVal lRow As Long, ByVal lCol As Long, ByVal vOldValue As Variant)
    Dim ListIndex As Long
    If Grd.CellType(lRow, lCol) = igCellTextCombo Then
        Grd.DevDbg 3, ListIndex
        KeyToStore = Cb.ItemValue(ListIndex)
    end if


Antony R.
2016-04-28T17:57:54Z
Originally Posted by: Igor/10Tec 

I have implemented this in a new interim build of iGrid and sent the link to download it to your mailbox.

One more thought about the functionality you need to implement:

Citação:

• When a user selects a listed town, to store the ID in the database, developer must do a binary recursive search in Combo Box items (or loop) to find the corresponding Index of the displayed text, so that you can retrieve the ItemValue and store it.
• When user enters a new town, developer must do again a binary recursive search in Combo Box items to find if the town is listed. If not, new Town must be added to the database and repopulate the combo box to include the new value or must find by code the proper index to insert it.



You may think about finding these values directly in the recordset you used to populate the combo list. Perhaps, the recordset object can provide you with its own methods to find what you need.



This is true.
I could have search in the recordset.
But imagine that combos could be filled with items that comes out from multiple table queries that run on large tables over the network and with multiple criteria.
The approach with listindex could be a zillion time faster... (and more simple, more robust, more easy to handle for the developer)
Otherwise developer should keep a global recordset for each combo box open (during population) and bind it somehow (internally) with the combo box. (waste of resources, complexity)
My opinion is that in later version you should add this property to the combo itself!

I'm happy that is someone like you behind that terrific grid tool that corresponds to our request.
Thanks again!