Cast NameValueListBase to DataView

Cast NameValueListBase to DataView

Old forum URL: forums.lhotka.net/forums/t/10199.aspx


jack.doe77 posted on Thursday, March 24, 2011

Hi,
I have NameValueListBase Class to populate ComboBox. I need to format the ComboBox to be multi-column.
Here's normally how I did :

Private Sub cbPeriod_Format( _
   ByVal sender As Object, ByVal e As System.Windows.Forms.ListControlConvertEventArgs) _
   Handles cbPeriod.Format
        Dim dv As DataRowView = TryCast(e.ListItem, DataRowView)
        If dv IsNot Nothing Then
            e.Value = String.Format("{0} {1}", dv.Item(0), dv.Item(1))
        End If
End Sub

It unable to convert NameValueListBase to DataRowView.
I've been googling try to figure out how it can be done with no luck. Could someone enlight me how can I retrieve NameValueListBase Key/Value so I can format it ? Thanks.

RockfordLhotka replied on Thursday, March 24, 2011

NVLB exists to address the single-key, single-value scenario that used to be so common in applications.

Today, with XAML and richer HTML UIs, that's not so common any more.

My recommendation is to use a ReadOnlyListBase containing ReadOnlyBase child objects to populate these modern UIs.

Don't try to use NVLB for something it isn't intended to solve.

jack.doe77 replied on Friday, March 25, 2011

Thanks Rocky for your suggestion.

Copyright (c) Marimer LLC