J
Jean-Pierre GUILLERON
I have encountered a different behavior beetween
Framework 1.0 and compact framework 1.1
Basically, I display a dataview in a combobox.
cb.datasource = Dataview
The behavior is different under 1.1, the dataview is not
displayed anymore.
I tried many things. And finally, I found a solution.
(give hereafter an exemple).
If you execute it in 1.0 and 1.1 you'll find a different
behavior.
This means the ascending/descending compatibility is not
garanteed.
Please help, thanks
'Incompatibility beetween Framework 1.0 and Compact
FrameWork 1.1 while processing combobox/dataview
'form with 2 combobox and one textbox
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
'Create Datatable with standard VB Sample
Dim dt As DataTable = DemonstrateDataTable()
dt.TableName = "Usine"
'Create Dataview
Dim dv As New DataView
dv = New DataView(dt)
dv.Sort = "ProductID"
'Create Dataset
Dim ds As New DataSet("Produits")
ds.Tables.Add(dt)
'Bind TextBox
txtUsine.DataBindings.Clear()
' Binds a TextBox control to a column in the
DataSet.
txtUsine.DataBindings.Add("Text",
ds, "Usine.ProductName")
'Bind First Combobox with DS
cbDS.DataBindings.Clear()
cbDS.BeginUpdate()
cbDS.Sorted = True
' Bind a Combobox control to a column in the
DataSet.
cbDS.DataBindings.Add("DisplayMember",
ds, "Usine.ProductName")
cbDS.DataSource = ds.Tables("Usine")
cbDS.DisplayMember = "ProductName"
cbDS.ValueMember = "ProductID"
cbDS.EndUpdate()
'Standard code given in the VB.Net documentation
cbDV.BeginUpdate()
cbDV.Sorted = True
'Load the DataView in the combobox datasource -
WITHOUT BINDING.
cbDV.DataSource = dv
cbDV.DisplayMember = "ProductName"
cbDV.ValueMember = "ProductID"
cbDV.EndUpdate()
'Trace
'It Works !
Debug.WriteLine("cbDS Count : " &
cbDS.Items.Count)
'Working with Framework 1.0, It doesn't Works
with Compact Framework 1.1
Debug.WriteLine("cbDV Count : " &
cbDV.Items.Count)
End Sub
Private Function DemonstrateDataTable() As DataTable
Dim myTable As DataTable
myTable = New DataTable
' add columns
Dim column As DataColumn
column = myTable.Columns.Add("ProductID", GetType
(Integer))
column.AutoIncrement = True
column = myTable.Columns.Add("ProductName",
GetType(String))
' populate DataTable.
Dim id As Integer
For id = 1 To 5
myTable.Rows.Add( _
New Object() {id, String.Format("product
{0}", id)})
Next id
Dim dv As DataView
dv = New DataView(myTable)
Return myTable
End Function
Framework 1.0 and compact framework 1.1
Basically, I display a dataview in a combobox.
cb.datasource = Dataview
The behavior is different under 1.1, the dataview is not
displayed anymore.
I tried many things. And finally, I found a solution.
(give hereafter an exemple).
If you execute it in 1.0 and 1.1 you'll find a different
behavior.
This means the ascending/descending compatibility is not
garanteed.
Please help, thanks
'Incompatibility beetween Framework 1.0 and Compact
FrameWork 1.1 while processing combobox/dataview
'form with 2 combobox and one textbox
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
'Create Datatable with standard VB Sample
Dim dt As DataTable = DemonstrateDataTable()
dt.TableName = "Usine"
'Create Dataview
Dim dv As New DataView
dv = New DataView(dt)
dv.Sort = "ProductID"
'Create Dataset
Dim ds As New DataSet("Produits")
ds.Tables.Add(dt)
'Bind TextBox
txtUsine.DataBindings.Clear()
' Binds a TextBox control to a column in the
DataSet.
txtUsine.DataBindings.Add("Text",
ds, "Usine.ProductName")
'Bind First Combobox with DS
cbDS.DataBindings.Clear()
cbDS.BeginUpdate()
cbDS.Sorted = True
' Bind a Combobox control to a column in the
DataSet.
cbDS.DataBindings.Add("DisplayMember",
ds, "Usine.ProductName")
cbDS.DataSource = ds.Tables("Usine")
cbDS.DisplayMember = "ProductName"
cbDS.ValueMember = "ProductID"
cbDS.EndUpdate()
'Standard code given in the VB.Net documentation
cbDV.BeginUpdate()
cbDV.Sorted = True
'Load the DataView in the combobox datasource -
WITHOUT BINDING.
cbDV.DataSource = dv
cbDV.DisplayMember = "ProductName"
cbDV.ValueMember = "ProductID"
cbDV.EndUpdate()
'Trace
'It Works !
Debug.WriteLine("cbDS Count : " &
cbDS.Items.Count)
'Working with Framework 1.0, It doesn't Works
with Compact Framework 1.1
Debug.WriteLine("cbDV Count : " &
cbDV.Items.Count)
End Sub
Private Function DemonstrateDataTable() As DataTable
Dim myTable As DataTable
myTable = New DataTable
' add columns
Dim column As DataColumn
column = myTable.Columns.Add("ProductID", GetType
(Integer))
column.AutoIncrement = True
column = myTable.Columns.Add("ProductName",
GetType(String))
' populate DataTable.
Dim id As Integer
For id = 1 To 5
myTable.Rows.Add( _
New Object() {id, String.Format("product
{0}", id)})
Next id
Dim dv As DataView
dv = New DataView(myTable)
Return myTable
End Function