ComboBox - index ./. ID of data record

Questions regarding syntax

ComboBox - index ./. ID of data record

Postby PMan » Sat Feb 19, 2011 6:27 pm

Hi

in my DB I have a category-table with i.e. 180 values and I will use this in an other table with a ComboBox. Now we aspect that the ID of the category table has gaps or I wish to sort the Combobox over the category-values. If I load the category-table values in the ComboBox the index of the ComboBox has not the same value as the ID of the category-table. When I stored the category in the other table by the ID, I have a problem to find the right catagory over the index in the ComboBox or I have the wrong value for the ID in the other table.

In MS Access the ComboBox has the possibility to store more then one value. So you can store values for ID, category and i.e. sort in the ComboBox and you can read the index of the ComboBox and the right ID of the data record at once.

Has anybody an idea for a solution of this problem?

/PMan
PMan
 
Posts: 145
Joined: Sat Jul 03, 2010 12:31 pm
Location: Switzerland

Re: ComboBox - index ./. ID of data record

Postby berndnoetscher » Sun Feb 20, 2011 3:26 pm

PMan wrote:Hi

in my DB I have a category-table with i.e. 180 values and I will use this in an other table with a ComboBox. Now we aspect that the ID of the category table has gaps or I wish to sort the Combobox over the category-values. If I load the category-table values in the ComboBox the index of the ComboBox has not the same value as the ID of the category-table. When I stored the category in the other table by the ID, I have a problem to find the right catagory over the index in the ComboBox or I have the wrong value for the ID in the other table.

In MS Access the ComboBox has the possibility to store more then one value. So you can store values for ID, category and i.e. sort in the ComboBox and you can read the index of the ComboBox and the right ID of the data record at once.

Has anybody an idea for a solution of this problem?

/PMan


Hi, you may use http://www.kbasic.com/doku.php?id=combobox#settag to set antother value for each entry of a combobox.
berndnoetscher
Site Admin
 
Posts: 1059
Joined: Tue Sep 25, 2007 9:37 am

Re: ComboBox - index ./. ID of data record

Postby PMan » Sun Feb 20, 2011 4:56 pm

Hi,

I have read SetTag, but I don't understand, how SetTag works. Have you any example?

/PMan
PMan
 
Posts: 145
Joined: Sat Jul 03, 2010 12:31 pm
Location: Switzerland

Re: ComboBox - index ./. ID of data record

Postby berndnoetscher » Mon Feb 21, 2011 11:36 am

PMan wrote:Hi,

I have read SetTag, but I don't understand, how SetTag works. Have you any example?

/PMan


e.g.

Code: Select all
  ComboBox0.SetCaption(1, "first entry changed")
  ComboBox0.SetTag(1, "custom id value or anything else for 1")
  MsgBox(ComboBox0.Tag(1))

berndnoetscher
Site Admin
 
Posts: 1059
Joined: Tue Sep 25, 2007 9:37 am

Re: ComboBox - index ./. ID of data record

Postby PMan » Sat Feb 26, 2011 3:52 pm

Thank you for information. I have implemented this in my code, but the ComboBox is empty. The print statement bevor filling the ComboBox shows the right values. The MsgBox after the filling is empty. What's going wrong?

Code: Select all
'     sCmbVal liefert ID, Value, ID, Value, ID ......   
      sCmbVal = CreateCMB(ho_DB, sFK)    'die FK-Tbl kann in einer anderen DB sein
      sCtlName = "cmb" & iSP
      sCtlType = "ComboBox"
      ControlAppend(sCtlName, sCtlType, sCtlGroup, _
          iOffsetX + iLabLen + iOffsetX, iPosH, iFldLen, vField[iSP,5], True)
      cmb = Control(sCtlName)
      cmb.FontName = sFont
      cmb.FontSize = iFontSize
'      cmb.Flat = True
      cmb.RemoveAll
      For iDS = 1 To sCmbVal.Length Step 2
'       Print iDS, Pos in cmb,      ID des Values,       Value
        Print iDS, CInt((iDS+1)/2), sCmbVal.String(iDS), sCmbVal.String(iDS+1)
        cmb.SetTag(CInt((iDS+1)/2), sCmbVal.String(iDS))
        cmb.SetCaption(CINT((iDS+1)/2), sCmbVal.String(iDS+1))
        MsgBox(cmb.Tag(CInt((iDS+1)/2)))
      Next iDS
      cmb.Value = sCmbVal.String(vField[iSP,6]
PMan
 
Posts: 145
Joined: Sat Jul 03, 2010 12:31 pm
Location: Switzerland


Return to Coding Questions

cron