adding extra items on top of ComboBox DataSource

D

DraguVaso

Hi,

I have a ComboBox of +- 15.000 items in it, via a DataSource. On Top of the
Items-list, I want to add some values, based on a user choise (via a filter
on the DataSource). Does anybody know how I can do this? When just adding
them with ComboBox.items.Insert I get an "Items collection cannot be
modified when the DataSource property is set".

Does anybody has a solution for this? i'm surely not the first to do this
:) I'm using VB.NET 2005 Beta 2.

Thanks a lot in advance,

Pieter


This is my source:

Dim dtbl As New DataTable
dtbl = MyWorkSpace.GetAllArticlesClient(61)

Dim dtv As New DataView(dtbl)
dtv.Sort = "NomArticle"

Dim dtvF As New DataView(dtbl)
dtvF.RowFilter = "NomArticle LIKE '*HUILE*'"
dtvF.Sort = "NomArticle"

Me.cmbTest.DataSource = dtv
Me.cmbTest.DisplayMember = "NomArticle"
Me.cmbTest.ValueMember = "CodeArticle"

Dim intX As Integer
For intX = (dtvF.Count - 1) To 0 Step -1
cmbTest.Items.Insert(0, dtvF.Item(intX))
Next
 
C

CMeStandingHere

I would just not set the datasource and insert them myself by looping
and then add the remaining
 
D

DraguVaso

I'm afraid that it isn't fast enough :-/

I'm trying this now, and it takes alreaddy several seconds to add 50 rows
like that...

Dim dtbl As New DataTable
dtbl = MyWorkSpace.GetAllArticlesClient(61)

Dim dtv As New DataView(dtbl)
'dtv.Sort = "NomArticle"

Dim dtvF As New DataView(dtbl)
dtvF.RowFilter = "NomArticle LIKE 'POMPE*'"
dtvF.Sort = "NomArticle"

Me.cmbTest.DataSource = dtv
Me.cmbTest.DisplayMember = "NomArticle"
Me.cmbTest.ValueMember = "CodeArticle"

Dim intX As Integer
Dim drow As DataRow
For intX = (dtvF.Count - 1) To 0 Step -1
drow = dtv.Table.NewRow
drow(0) = dtvF.Item(intX).Item(0)
drow(1) = dtvF.Item(intX).Item(1)
drow(2) = dtvF.Item(intX).Item(2)
dtv.Table.Rows.InsertAt(drow, 0)
'cmbTest.Items.Insert(0, dtvF.Item(intX))
Next
 
C

Cor Ligthert [MVP]

Pieter,

I saw your datasource is a datatable, I would add a column to the datatable.
Than add the rows with in the NewColumn something as an A or whatever and
set the defaultview.Sort of the datatable to

Tabeleke.Datasoure = "Collomeke Desc"

I hope you like the idea.

Cor
 
C

Chris

DraguVaso said:
I'm afraid that it isn't fast enough :-/

I'm trying this now, and it takes alreaddy several seconds to add 50 rows
like that...

Dim dtbl As New DataTable
dtbl = MyWorkSpace.GetAllArticlesClient(61)

Dim dtv As New DataView(dtbl)
'dtv.Sort = "NomArticle"

Dim dtvF As New DataView(dtbl)
dtvF.RowFilter = "NomArticle LIKE 'POMPE*'"
dtvF.Sort = "NomArticle"

Me.cmbTest.DataSource = dtv
Me.cmbTest.DisplayMember = "NomArticle"
Me.cmbTest.ValueMember = "CodeArticle"

Dim intX As Integer
Dim drow As DataRow
For intX = (dtvF.Count - 1) To 0 Step -1
drow = dtv.Table.NewRow
drow(0) = dtvF.Item(intX).Item(0)
drow(1) = dtvF.Item(intX).Item(1)
drow(2) = dtvF.Item(intX).Item(2)
dtv.Table.Rows.InsertAt(drow, 0)
'cmbTest.Items.Insert(0, dtvF.Item(intX))
Next

Why are you using InsertAt? I believe that it requires coping of all
the other current items to make room for the one item. If you do a
straight insert does it work at the same speed as the databind?
 
D

DraguVaso

I use InsertAt, beauce I want them to be the first items to be shown in the
ComboBox, so I thought it is better to add them at the beginning...
A normal insert (Add) works indeed faster in my opinion.
 
D

DraguVaso

I do indeed like the idea: I though of it myself yesterday. But won't it
take to much overhead adding the extra column? I'll try it today :)

Thanks!
 
Top