List Info

Thread: ListBox Question




ListBox Question
user name
2006-03-01 17:13:07
I have a ListBox which is bound to a DataSet (the DataSet is
returned
from a call to a Web Service).

I need to process multiple user selections and place them in
an array
of type int. I wrote the following code to do so:

int arrayLength = listBox1.SelectedItems.Count;
int[] divisonArray = new int[arrayLength];

for (int i= 0 ;i < arrayLength;i++)
{
   divisonArray[i] =
int.Parse(listBox1.SelectedItems[i].Text);
}

The problem is that this won't parse.
listBox1.SelectedItems[i] is
returning a DataRowView, rather than the actual value being
displayed
in the list box.

This isn't a binding issue, as far as I know. The control
is correctly
bound, and the DisplayMember is set properly. The division
numbers are
being displayed in the list, as they should be.

How do I get the actual division number that is being
displayed in the
list? I have tried numerous things, none of which have
worked.

The list box is using MultiExtended selection mode.

Help would be much appreciated!


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C# Developers" group.
To post to this group, send email to CSDevelopersgooglegroups.com
To unsubscribe from this group, send email to
CSDevelopers-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/CSDevelopers
-~----------~----~----~----~------~----~------~--~---

ListBox Question
user name
2006-03-02 15:30:54
I apologize, I don't know the WinForms ListBox class so
well, but two
things I would try:

1.  divisonArray[i] =
int.Parse(listBox1.SelectedItems[i].ToString());

2.  If number 1 doesn't work, set a breakpoint on the line
of code
inside the for loop (that starts with divisionArray).  When
your code
hits the breakpoint, add a Watch item for
listBox1.SelectedItems[i].
This will allow you to drill down into the object to find
out where
your value is hiding.

I hope this helps.  I'm still a rookie C# developer, but I
know where
in the code to look for answers.

Good luck with your ListBox!  

Kerry


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C# Developers" group.
To post to this group, send email to CSDevelopersgooglegroups.com
To unsubscribe from this group, send email to
CSDevelopers-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/CSDevelopers
-~----------~----~----~----~------~----~------~--~---

ListBox Question
user name
2006-03-11 05:49:04
Dear Sheila,
you should cast your data to the type of data that you want !
 
Enjoy !


 ;
On 3/1/06, marmaxx <tjx.com">sheila_martintjx.com&gt; wrote:

I have a ListBox which is bound to a DataSet (the DataSet is returned
from a call to a Web Service).

I need to process multiple user selections and place them in an array
of type int. I wrote the following code to do so:

int arrayLength = listBox1.SelectedItems.Count;
int[] divisonArray = new int[arrayLength];

for (int i= 0 ;i < arrayLength;i++)
{
&nbsp; divisonArray[i] = int.Parse(listBox1.SelectedItems[i].Text);
}

The problem is that this won't parse. listBox1.SelectedItems[i] is
returning a DataRowView, rather than the actual value being displayed
in the list box.

This isn't a binding issue, as far as I know. The control is correctly
bound, and the DisplayMember is set properly. The division numbers are
being displayed in the list, as they should be.

How do I get the actual division number that is being displayed in the
list? I have tried numerous things, none of which have worked.

The list box is using MultiExtended selection mode.

Help would be much appreciated! MCSE+I
CIW ASSOCIATE & PROFESSIONAL
A+
MSVB MCP
Java Devloper
Java Applet Designer
ITMCL
ACCP
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C# Developers" group.
To post to this group, send email to CSDevelopersgooglegroups.com
To unsubscribe from this group, send email to CSDevelopers-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/CSDevelopers
-~----------~----~----~----~------~----~------~--~---

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )