![]() |
![]() |
Value item is a mapping from a data source value to text and picture that will be displayed in a grid cell. Such a mapping is represented with the SGValueItem object. Each column has a ValueItems property that contains a collection of value items for that column.
To add value items to a column you can use the following code:
SGGrid1.Columns(1).Control.Type = sgCellDropList SGGrid1.Columns(1).ValueItems.Add 1, "First" SGGrid1.Columns(1).ValueItems.Add 2, "Second", LoadPicture("Second.bmp") SGGrid1.Columns(1).ValueItems.Add 3, "Third", 1
The Default property can be used to indicate which item to show if underlying value does not match any item in the value items collection. This property does not have effect if the LimitToList property us set to True.
The ValueItemError event occurs when the user enters data that is not in the value items list and value items are enabled for the edited column. This event is useful when you want to add a new value to the SGValueItems collection.When you sort a column with value items enabled, it will be sorted by its underlying data. To sort by display data, you can use custom sort or you can sort data in your code. For example, you can use an SQL statement or you can have a hidden column which you use for a sort operation. The Outlook Demo example uses various approaches for data sorting.
The code below demonstrates how to use and populate the ValueItems collection:
Private Sub SGGrid1_OnInit()
Dim rs As Object
Dim i As Integer
Const adInteger = 3
Const adBSTR = 8
Set rs = CreateObject("ADODB.Recordset")
rs.Fields.Append "Id", adInteger
rs.Fields.Append "Caption", adBSTR, 50
rs.Open
For i = 1 To 10
rs.AddNew
rs!Id = i
rs!Caption = "Item " & Trim(i)
rs.Update
Next
SGGrid1.DataMode = sgBound
Set SGGrid1.DataSource = rs
With SGGrid1.Columns("Id")
.Width = 2000
.Control.Type = sgCellDropList
.HeadingStyle.TextAlignment = sgAlignLeftCenter
.Style.TextAlignment = sgAlignLeftCenter
.Control.PopupStyle.TextAlignment = sgAlignLeftCenter
While Not rs.EOF
'if you try to add value items with the code
'below the grid will accept field object not string
'.ValueItems.Add rs!Id, rs!Caption
'just convert it to long/string
.ValueItems.Add CLng(rs!Id), CStr(rs!Caption)
rs.MoveNext
Wend
End With
rs.MoveFirst
End Sub
See Also
ValueItems | SGControl | Samples - ValueItems | Samples - Controls