databound listbox question

  • Thread starter Thread starter joe
  • Start date Start date
J

joe

I actually have 2 questions:

1) Is databinding the fastest way to load a listbox from sqlserver?
speed is crucial and I want to make sure i'm populating it the fastest
way i can

2) Also, i'm having trouble getting the selected items in the
listbox.

Will simply using the Items property (with the index) not give me
access to the value?:

For intIndex = lstStatus.SelectedIndex To lstStatus.Items.Count - 1
strTest = strTest & lstStatus.Items(intIndex)
Next

what's so frustrating is that i'm actually doing this for Excel using
VSTO and everytime i try to use the .Items(intIndex) - Excel
completely crashes on me.

anybody point me to an example or hint?

TIA!
Joe
 
Joe,
1) Is databinding the fastest way to load a listbox from sqlserver?
speed is crucial and I want to make sure i'm populating it the fastest
way i can

The time done with reading the rows accoording with the question what
loading of the listbox is the fastest is comparing parts of seconds with
parts of milliseconds.
2) Also, i'm having trouble getting the selected items in the
listbox.

Will simply using the Items property (with the index) not give me
access to the value?:

For intIndex = lstStatus.SelectedIndex To lstStatus.Items.Count - 1
strTest = strTest & lstStatus.Items(intIndex)
Next
Do you have Option Strict On in top of your program?

Probably you only have to add ".ToString" after that (intIndex)

I hope this helps?

Cor
 
Cor-
Thank you very much! The .ToString is definitely a step in the right
direction as it's at least keeping Excel from crashing on me, but i'm
still having one problem.

When I use the .ToString, i'm returned "System.Data.DataRowView" so
i'm assuming it's because it's databound and I must somehow use a
datarowview object to access the value?

any help would be appreciated-

thanks-
joe
 
Joe,

I think that my thought was that because you where asking it, you had not
binded data to the listbox yet.
and that as well because you where using the item.

Probably because when you use a datasource that is taken for an operation as
you do.

However to keep it in the way you did, this did work for me as well.

\\\
strTest = strTest & DirectCast(ListBox1.Items(intIndex),
DataRowView)("Name").ToString
///
("Name" is the used datamember so that you have to change for yours)

While I had expect something as
\\\
strTest = strTest & DirectCast(ListBox1.DataSource,
DataView)(intIndex)("Name").ToString
///
What works as well. For "DirectCast(ListBox1.DataSource, DataView)" you can
directly place the datasource.

I hope it helps?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top