S
Shaun Wilde
Hi all
I've been trying to make my wee app a bit faster and and I am seeking to
reduce the time it takes to load my data into the combo boxes.
Now I have a search that is quite expensive but is used by 5 comboboxes on
the same form.
However I hit a snag. If I use the same Dataset for the datasource for each
combobox then all the comboboxes become linked - ie if you change one you
change then all.
At first I thought it was DataSets so I tried it with my own ArrayList but
no it seems that this is what happens - I don't understand the rational at
all behind this 'designed' behaviour but it is not what I expected. This
behaviour is seen on both Compact and Full .NET frameworks and in C# and
VB.NET.
So I thought about cloning my DataSet so I can get it once and use clones
for each control - but no MS have taken away the .Copy method from DataSet
and the only way I can find to make a copy is via XmlReader and is more time
consuming than the search (along the lines of "select a,b from x order by
a") which was surprising.
Now in the Full Framework when we load DataSets we have a BeginInit/EndInit
combo which does the old WM_SETREDRAW message to the combobox to disable
updating but again this method has been pulled (so I'll have to spend time
working out if I can do this natively - though how I'll find my combobox
will be a miracle - I may just have to blanket bomb them all on a form).
So I've tried pulling my control off the form - loading it - and then
putting it back - as mentioned in a past newsgroup posting (not convinced
yet)
I tried not using a DataSet but make my own collection of ItemPair objects
while iterating using a SqlCeDataReader (some improvement) and then loading
that as the DataSource
I tried not using DataSource property but assing them to the array directly
using Items.Add(...) but the ValueMember property is ignored.
So does anyone have a fast DataSet copier or code they use to see if I am
doing something daft?
Can someone suggest a better way of loading a combobox with >100 items?
Can anyone explain why using the same array for a common datasource exhibits
the described behaviour? (see code below)
Thanks
Shaun
PS - code follows
Dim ar As New ArrayList
ar.Add(New ItemPair("String 1", 1))
ar.Add(New ItemPair("String 2", 2))
ar.Add(New ItemPair("String 3", 3))
ar.Add(New ItemPair("String 4", 4))
ar.Add(New ItemPair("String 5", 5))
ar.Add(New ItemPair("String 6", 6))
ComboBox1.DisplayMember = "First" ' the name of the property which contains
the string data
ComboBox1.ValueMember = "Second" ' the name of the property which contains
the int data
ComboBox1.DataSource = ar
ComboBox2.DisplayMember = "First"
ComboBox2.ValueMember = "Second"
ComboBox2.DataSource = ar
ComboBox2.SelectedValue = 3 ' both combo boxes focus on the same element
I've been trying to make my wee app a bit faster and and I am seeking to
reduce the time it takes to load my data into the combo boxes.
Now I have a search that is quite expensive but is used by 5 comboboxes on
the same form.
However I hit a snag. If I use the same Dataset for the datasource for each
combobox then all the comboboxes become linked - ie if you change one you
change then all.
At first I thought it was DataSets so I tried it with my own ArrayList but
no it seems that this is what happens - I don't understand the rational at
all behind this 'designed' behaviour but it is not what I expected. This
behaviour is seen on both Compact and Full .NET frameworks and in C# and
VB.NET.
So I thought about cloning my DataSet so I can get it once and use clones
for each control - but no MS have taken away the .Copy method from DataSet
and the only way I can find to make a copy is via XmlReader and is more time
consuming than the search (along the lines of "select a,b from x order by
a") which was surprising.
Now in the Full Framework when we load DataSets we have a BeginInit/EndInit
combo which does the old WM_SETREDRAW message to the combobox to disable
updating but again this method has been pulled (so I'll have to spend time
working out if I can do this natively - though how I'll find my combobox
will be a miracle - I may just have to blanket bomb them all on a form).
So I've tried pulling my control off the form - loading it - and then
putting it back - as mentioned in a past newsgroup posting (not convinced
yet)
I tried not using a DataSet but make my own collection of ItemPair objects
while iterating using a SqlCeDataReader (some improvement) and then loading
that as the DataSource
I tried not using DataSource property but assing them to the array directly
using Items.Add(...) but the ValueMember property is ignored.
So does anyone have a fast DataSet copier or code they use to see if I am
doing something daft?
Can someone suggest a better way of loading a combobox with >100 items?
Can anyone explain why using the same array for a common datasource exhibits
the described behaviour? (see code below)
Thanks
Shaun
PS - code follows
Dim ar As New ArrayList
ar.Add(New ItemPair("String 1", 1))
ar.Add(New ItemPair("String 2", 2))
ar.Add(New ItemPair("String 3", 3))
ar.Add(New ItemPair("String 4", 4))
ar.Add(New ItemPair("String 5", 5))
ar.Add(New ItemPair("String 6", 6))
ComboBox1.DisplayMember = "First" ' the name of the property which contains
the string data
ComboBox1.ValueMember = "Second" ' the name of the property which contains
the int data
ComboBox1.DataSource = ar
ComboBox2.DisplayMember = "First"
ComboBox2.ValueMember = "Second"
ComboBox2.DataSource = ar
ComboBox2.SelectedValue = 3 ' both combo boxes focus on the same element