Home › Forums › WinForms controls › Xceed Grid for WinForms › ComboBox with associated data
-
AuthorPosts
-
#17373 |
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
displayedPublic ItemData As Integer ‘ associated data
Public Overrides Function ToString() As
StringReturn ItemText
End Function
End Class
I created
by combo box editor:Private TestComboBox As New WinComboBox()
Private ListBoxData
As New ListItemI added data to the combo box:
ListBoxData = New
ListItemListBoxData.ItemText = “Item 1”
ListBoxData.ItemData = 1
TestComboBox.Items.Add(ListBoxData)
ListBoxData = New
ListItemListBoxData.ItemText = “Item 2”
ListBoxData.ItemData = 2
TestComboBox.Items.Add(ListBoxData)
I created the
columns, attached the combo box to the column, and added the handlergrdData.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_LeavingEditThe “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?
Imported from legacy forums. Posted by Morgan (had 2378 views)
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”
Imported from legacy forums. Posted by Mohamed [Xceed] (had 396 views)
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.
Imported from legacy forums. Posted by Morgan (had 454 views)
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)
Imported from legacy forums. Posted by Credits (had 1110 views)
-
AuthorPosts
- You must be logged in to reply to this topic.