Welcome to the Xceed Community | Help
Community Search  
More Search Options

ComboBox with associated data

Sort Posts: Previous Next
  •  02-10-2010, 8:59 AM Post no. 25732

    ComboBox with associated data

     

    I have two columns:

     

    1. “Status” an unbound column which contains a ComboBox with a selection of status type descriptions.

     

    2. “StatusID” a bound, invisible column that contains the StatusID (an integer value)

     

    I am trying to change the StatusID value based on the Status value the user changes via a combo box.

     

    What I have so far is:

     

    I created the following class:

       Public Class ListItem

          Public ItemText As String   ' what is displayed

          Public ItemData As Integer  ' associated data

          Public Overrides Function ToString() As String

             Return ItemText

          End Function

       End Class

     

    I created by combo box editor:

       Private TestComboBox As New WinComboBox()

       Private ListBoxData As New ListItem

     

    I added data to the combo box:

       ListBoxData = New ListItem

       ListBoxData.ItemText = "Item 1"

       ListBoxData.ItemData = 1

       TestComboBox.Items.Add(ListBoxData)

       ListBoxData = New ListItem

       ListBoxData.ItemText = "Item 2"

       ListBoxData.ItemData = 2

       TestComboBox.Items.Add(ListBoxData)

     

    I created the columns, attached the combo box to the column, and added the handler

       grdData.Columns.Add(New Column("Status", GetType(String)))

       grdData.Columns("Status").CellEditorManager = New ComboBoxEditor(TestComboBox)

       grdData.Columns.Add(New Column("StatusID", GetType(Integer)))

       AddHandler grdData.DataRowTemplate.Cells("Status").LeavingEdit, AddressOf Status_LeavingEdit

     

    The “Status” cell updates as it should, but I can not figure how to update the “StatusID” cell.  The following does not work:

       Private Sub Status_LeavingEdit(ByVal sender As Object, ByVal e As LeavingEditEventArgs)

          Dim Cell As Cell = CType(sender, Cell)

          ListBoxData = CType(Cell.Value, ListItem)

          'MsgBox(ListBoxData.ItemData.ToString)

       End Sub

     

    Can anyone help?

    Filed under:
  •  02-11-2010, 2:20 PM Post no. 25762 in reply to 25732

    Re: ComboBox with associated data

    Hi Morgan,

    You could implement the ValueChanged event on the cells of the “Status” unbound column. Once the value has changed, a delegate method will be called where you could access the “StatusID” field value of the ParentRow and modify as desired.

    Example:

     

    Dim Cell As Cell = CType(sender, Cell)

    Cell.ParentRow.Cells(“StatusID”).Value =”New Value”

     

     


    Xceed - Software Developer and Technical Support
  •  02-12-2010, 8:00 AM Post no. 25767 in reply to 25762

    Re: ComboBox with associated data

    My problem is that "New Value" needs to come from the TestComboBox that the user used to change the "Status" description cell.  I don't know how to get the associated data (ItemData) from the combo box the user used to select the "Status".

    Dim Cell As Cell = CType(sender, Cell)

    ListBoxData = CType(Cell.Value, ListItem)

    Cell.ParentRow.Cells("StatusID").value = ListBoxData.ItemData

    The only value that matters is the StatusID (which is a number).  The Status cell is used to provide the user with a description of what this StatusID number represents. 

     

  •  04-04-2010, 8:35 AM Post no. 26393 in reply to 25767

    Re: ComboBox with associated data

    Try working on Combobox viewer and editor component, they will simplify your headache for maintaining status description and ID columns on the grid. Moreover its easy just with 4 lines of code, you get your things worked out.

     Hope below few lines help you understand.

    Rgds,

    Kalpesh..

    Dim CBOViewer_Company = New ComboBoxViewer(dsMasters, "Mst_Company", "AutoID", "%CName%")

    Dim CBOEditor_Company = New ComboBoxEditor(dsMasters, "Mst_Company", "AutoID", "%CName%")

    detail.Columns("CompanyID").CellViewerManager = CBOViewer_Company

    detail.Columns("CompanyID").CellEditorManager = CBOEditor_Company

    detail.Columns("CompanyID").Title = "Company"

    XceedGridContainer.SetWinComboBoxStyle(CBOEditor.TemplateControl)

    CBOEditor_Company.TemplateControl.SearchMode = Xceed.Editors.SearchMode.FullText

    CBOEditor_Company.TemplateControl.DropDownSize = New Size(250, 150)

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.