Hi Aussie,
Thanks for the feedback.
Actually, what Marina suggested is storing the actual TimeSpan value in
the
values of the item of Combox, instead of storing it in the text
representation of the item. To use this approach, your item that is added
into Combobox.Items collection should a customized object, which contains
at least 2 properties: text representation and value representation. Below
code snippet demonstrate this approach:
Public Class TimeObject
Private _timeobj As TimeSpan
Public ReadOnly Property TimeText() As String
Get
Return _timeobj.ToString()
End Get
End Property
Public Property TimeValue() As TimeSpan
Get
Return _timeobj
End Get
Set(ByVal value As TimeSpan)
_timeobj = value
End Set
End Property
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim i As Integer
For i = 0 To 5
Dim item As New TimeObject
item.TimeValue = item.TimeValue.Add(New TimeSpan(i, 0, 0))
Me.ComboBox1.Items.Add(item)
Next
Me.ComboBox1.DisplayMember = "TimeText"
Me.ComboBox1.ValueMember = "TimeValue"
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
Dim selected_obj As TimeObject =
CType(Me.ComboBox1.Items(Me.ComboBox1.SelectedIndex), TimeObject)
Dim ts As TimeSpan = selected_obj.TimeValue
End Sub
Note: while retrieving TimeSpan from database, you should store the time
value in TimeValue property of TimeObject. By using this approach, you may
leverage .Net winform databinding to use the time value.
However, if your design does not want to store time value from database in
a customized TimeObject, you may just add the text representation as the
item to the Combobox items collection. Then you should use
TimeSpan.Parse()
to parse the text representation of the item, like this: Dim ts As
TimeSpan
= TimeSpan.Parse("11:00")
Hope this helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.