By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,213 Members | 1,984 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,213 IT Pros & Developers. It's quick & easy.

ListBox Question

P: n/a
Hi all,

I need to populate a listbox from a table column. The column has multiple
entries of usernames and I need to pull a unique set of usernames. The table
is part of an untyped Dataset that is created during runtime. There is no
DataAdapter. On an SQL server I would just pull a Unique Set but that
doesn't seem to be an option in my case. So I created the code below. It
works but it is very slow bringing up the list box. Is there a better way of
doing this?
Also, after the listbox is displayed how can I capture which username(s) the
user has highlighted when he/she clicks on a button called "doIt".

Public Sub selList()

Dim dcPick As New DataColumn("User", GetType(String))
dcPick.Unique = True
tbPick.Columns.Add(dcPick)

Dim pRows() As DataRow = _dt.Select()
Dim pSel As DataRow
For Each pSel In pRows
Try
tbPick.ImportRow(pSel)
Catch
Exit Try
End Try
Next
End Sub

Thanks for your help,

Claus
Nov 21 '05 #1
Share this Question
Share on Google+
28 Replies


P: n/a
Claus,

The way you use now the Try catch block is the worsest way it can be,

You want to create a "distinct" table and even an easy one in my opinion.

The simplest way looks for me in this case,
Create a dataview
Set the sort of that to your distict column
Loop through that dataview
Test everytime for the earlier one when equal you skip when uneaqual you do
that import.

(what is that tbpick by the way?, it is a lot of guessing now, so I cannot
write some sample code)

Cor

"cjobes" <cj****@nova-tech.org> schreef in bericht
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi all,

I need to populate a listbox from a table column. The column has multiple
entries of usernames and I need to pull a unique set of usernames. The
table
is part of an untyped Dataset that is created during runtime. There is no
DataAdapter. On an SQL server I would just pull a Unique Set but that
doesn't seem to be an option in my case. So I created the code below. It
works but it is very slow bringing up the list box. Is there a better way
of
doing this?
Also, after the listbox is displayed how can I capture which username(s)
the
user has highlighted when he/she clicks on a button called "doIt".

Public Sub selList()

Dim dcPick As New DataColumn("User", GetType(String))
dcPick.Unique = True
tbPick.Columns.Add(dcPick)

Dim pRows() As DataRow = _dt.Select()
Dim pSel As DataRow
For Each pSel In pRows
Try
tbPick.ImportRow(pSel)
Catch
Exit Try
End Try
Next
End Sub

Thanks for your help,

Claus

Nov 21 '05 #2

P: n/a
Hi Cor,

I new I would end up with the worst solution *G*. VB.Net is a painful
learning experience.

tbPick is a temp table that I create for the purpose of getting the unique
set of usernames. Because I use it in different subs I dimmed it at the form
class level. That's why you don't see it in the code. I need to catch the
list of possible usernames for the duration of the program run for reuse.
The user is supposed to select one or more users and I run a Select (where
username(s) equal... against another table.

In another sub I have set the listbox to:
Me.pickBox.DataSource = tbPick
Me.pickBox.DisplayMember = "User"

I also haven't figured out how I can catch which user(s) the user selects
before he/she hits the "go" button.

Thanks,
Claus
"Cor Ligthert" <no************@planet.nl> wrote in message
news:eL**************@TK2MSFTNGP15.phx.gbl...
Claus,

The way you use now the Try catch block is the worsest way it can be,

You want to create a "distinct" table and even an easy one in my opinion.

The simplest way looks for me in this case,
Create a dataview
Set the sort of that to your distict column
Loop through that dataview
Test everytime for the earlier one when equal you skip when uneaqual you do that import.

(what is that tbpick by the way?, it is a lot of guessing now, so I cannot
write some sample code)

Cor

"cjobes" <cj****@nova-tech.org> schreef in bericht
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi all,

I need to populate a listbox from a table column. The column has multiple entries of usernames and I need to pull a unique set of usernames. The
table
is part of an untyped Dataset that is created during runtime. There is no DataAdapter. On an SQL server I would just pull a Unique Set but that
doesn't seem to be an option in my case. So I created the code below. It
works but it is very slow bringing up the list box. Is there a better way of
doing this?
Also, after the listbox is displayed how can I capture which username(s)
the
user has highlighted when he/she clicks on a button called "doIt".

Public Sub selList()

Dim dcPick As New DataColumn("User", GetType(String))
dcPick.Unique = True
tbPick.Columns.Add(dcPick)

Dim pRows() As DataRow = _dt.Select()
Dim pSel As DataRow
For Each pSel In pRows
Try
tbPick.ImportRow(pSel)
Catch
Exit Try
End Try
Next
End Sub

Thanks for your help,

Claus


Nov 21 '05 #3

P: n/a
Claus,

Is this something you want to archieve

\\\
Private Sub Form12_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'creating a very simple datatable
Dim dt As New DataTable
dt.Columns.Add("user")
Dim names() As String = New String() {"Geoff", "Cor", _
"Herfried", "Jay", "Herfried"}
For Each usern As String In names
Dim dr As DataRow = dt.NewRow
dr(0) = usern
dt.Rows.Add(dr)
Next
'sample distinct
Dim dtclone As DataTable = dt.Clone
Dim dv As New DataView(dt)
dv.Sort = "user"
Dim myselold As String = ""
For i As Integer = 0 To dv.Count - 1
If myselold <> dv(i)("user").ToString Then
Dim drn As DataRow = dtclone.NewRow
For y As Integer = 0 To drn.ItemArray.Length - 1
drn(y) = dv(i)(y)
Next
myselold = dv(i)("user").ToString
dtclone.Rows.Add(drn)
End If
Next
ListBox1.DataSource = dtclone
ListBox1.DisplayMember = "user"
'One Herfried is enough
End Sub
///

I hope this helps?

Cor
"cjobes" <cj****@nova-tech.org>
I new I would end up with the worst solution *G*. VB.Net is a painful
learning experience.

tbPick is a temp table that I create for the purpose of getting the unique
set of usernames. Because I use it in different subs I dimmed it at the
form
class level. That's why you don't see it in the code. I need to catch the
list of possible usernames for the duration of the program run for reuse.
The user is supposed to select one or more users and I run a Select (where
username(s) equal... against another table.

In another sub I have set the listbox to:
Me.pickBox.DataSource = tbPick
Me.pickBox.DisplayMember = "User"

I also haven't figured out how I can catch which user(s) the user selects
before he/she hits the "go" button.

Thanks,
Claus
"Cor Ligthert" <no************@planet.nl> wrote in message
news:eL**************@TK2MSFTNGP15.phx.gbl...
Claus,

The way you use now the Try catch block is the worsest way it can be,

You want to create a "distinct" table and even an easy one in my opinion.

The simplest way looks for me in this case,
Create a dataview
Set the sort of that to your distict column
Loop through that dataview
Test everytime for the earlier one when equal you skip when uneaqual you

do
that import.

(what is that tbpick by the way?, it is a lot of guessing now, so I
cannot
write some sample code)

Cor

"cjobes" <cj****@nova-tech.org> schreef in bericht
news:%2****************@TK2MSFTNGP10.phx.gbl...
> Hi all,
>
> I need to populate a listbox from a table column. The column has multiple > entries of usernames and I need to pull a unique set of usernames. The
> table
> is part of an untyped Dataset that is created during runtime. There is no > DataAdapter. On an SQL server I would just pull a Unique Set but that
> doesn't seem to be an option in my case. So I created the code below.
> It
> works but it is very slow bringing up the list box. Is there a better way > of
> doing this?
> Also, after the listbox is displayed how can I capture which
> username(s)
> the
> user has highlighted when he/she clicks on a button called "doIt".
>
> Public Sub selList()
>
> Dim dcPick As New DataColumn("User", GetType(String))
> dcPick.Unique = True
> tbPick.Columns.Add(dcPick)
>
> Dim pRows() As DataRow = _dt.Select()
> Dim pSel As DataRow
> For Each pSel In pRows
> Try
> tbPick.ImportRow(pSel)
> Catch
> Exit Try
> End Try
> Next
> End Sub
>
> Thanks for your help,
>
> Claus
>
>



Nov 21 '05 #4

P: n/a
Cor,

Thanks for the sample. I might not understand this right but I can't do the

Dim names() As String = New String() {"Geoff", "Cor", "Herfried", "Jay",
"Herfried"}

because I don't know the usernames that are in the tbSelect table until I
read them.

Also, how do I find out which name(s) the user selected from the listbox?

Claus
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Claus,

Is this something you want to archieve

\\\
Private Sub Form12_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'creating a very simple datatable
Dim dt As New DataTable
dt.Columns.Add("user")
Dim names() As String = New String() {"Geoff", "Cor", _
"Herfried", "Jay", "Herfried"}
For Each usern As String In names
Dim dr As DataRow = dt.NewRow
dr(0) = usern
dt.Rows.Add(dr)
Next
'sample distinct
Dim dtclone As DataTable = dt.Clone
Dim dv As New DataView(dt)
dv.Sort = "user"
Dim myselold As String = ""
For i As Integer = 0 To dv.Count - 1
If myselold <> dv(i)("user").ToString Then
Dim drn As DataRow = dtclone.NewRow
For y As Integer = 0 To drn.ItemArray.Length - 1
drn(y) = dv(i)(y)
Next
myselold = dv(i)("user").ToString
dtclone.Rows.Add(drn)
End If
Next
ListBox1.DataSource = dtclone
ListBox1.DisplayMember = "user"
'One Herfried is enough
End Sub
///

I hope this helps?

Cor
"cjobes" <cj****@nova-tech.org>
I new I would end up with the worst solution *G*. VB.Net is a painful
learning experience.

tbPick is a temp table that I create for the purpose of getting the unique set of usernames. Because I use it in different subs I dimmed it at the
form
class level. That's why you don't see it in the code. I need to catch the list of possible usernames for the duration of the program run for reuse. The user is supposed to select one or more users and I run a Select (where username(s) equal... against another table.

In another sub I have set the listbox to:
Me.pickBox.DataSource = tbPick
Me.pickBox.DisplayMember = "User"

I also haven't figured out how I can catch which user(s) the user selects before he/she hits the "go" button.

Thanks,
Claus
"Cor Ligthert" <no************@planet.nl> wrote in message
news:eL**************@TK2MSFTNGP15.phx.gbl...
Claus,

The way you use now the Try catch block is the worsest way it can be,

You want to create a "distinct" table and even an easy one in my opinion.
The simplest way looks for me in this case,
Create a dataview
Set the sort of that to your distict column
Loop through that dataview
Test everytime for the earlier one when equal you skip when uneaqual you
do
that import.

(what is that tbpick by the way?, it is a lot of guessing now, so I
cannot
write some sample code)

Cor

"cjobes" <cj****@nova-tech.org> schreef in bericht
news:%2****************@TK2MSFTNGP10.phx.gbl...
> Hi all,
>
> I need to populate a listbox from a table column. The column has

multiple
> entries of usernames and I need to pull a unique set of usernames.
The > table
> is part of an untyped Dataset that is created during runtime. There

is no
> DataAdapter. On an SQL server I would just pull a Unique Set but that
> doesn't seem to be an option in my case. So I created the code below.
> It
> works but it is very slow bringing up the list box. Is there a better

way
> of
> doing this?
> Also, after the listbox is displayed how can I capture which
> username(s)
> the
> user has highlighted when he/she clicks on a button called "doIt".
>
> Public Sub selList()
>
> Dim dcPick As New DataColumn("User", GetType(String))
> dcPick.Unique = True
> tbPick.Columns.Add(dcPick)
>
> Dim pRows() As DataRow = _dt.Select()
> Dim pSel As DataRow
> For Each pSel In pRows
> Try
> tbPick.ImportRow(pSel)
> Catch
> Exit Try
> End Try
> Next
> End Sub
>
> Thanks for your help,
>
> Claus
>
>



Nov 21 '05 #5

P: n/a
Claus,

As I wrote in the sample, that is to create the sample datatable.
Thanks for the sample. I might not understand this right but I can't do
the

Dim names() As String = New String() {"Geoff", "Cor", "Herfried", "Jay",
"Herfried"}

because I don't know the usernames that are in the tbSelect table until I
read them.


I assume you have somewhere your own datatable with usernames.

Cor
Nov 21 '05 #6

P: n/a
Cor,

Dohhhhhh, now I feel really stupid. Ok, I did adapted your sample to use the
existing table. In the designer view the i and y are underlined, saying they
are not declared and the "AS" is underlined in both cases (for i as
integer=0...), saying "syntax error".

I also did some search on google groups to find out more about the listbox
selected item. I tried:
Dim pickTry = pickBox.GetItemText(pickBox.SelectedItems)
but when I halt the program and check the value of pickTry it says the
object name and not the actual value.

Claus

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl...
Claus,

As I wrote in the sample, that is to create the sample datatable.
Thanks for the sample. I might not understand this right but I can't do
the

Dim names() As String = New String() {"Geoff", "Cor", "Herfried", "Jay", "Herfried"}

because I don't know the usernames that are in the tbSelect table until I read them.


I assume you have somewhere your own datatable with usernames.

Cor

Nov 21 '05 #7

P: n/a
Cor,

I fixed that syntax error by declaring i and y before starting the routine
and taking the AS out of the code. It works very well and much faster than
before. Thanks.

I still can't get the selected value into a variable. The variable holds the
Type instead of the actual value. I also can't select more than one value in
the listbox. I have seen apps doing that so I know it's possible. I will do
some further reseach on it.

Thanks again,
Claus
"cjobes" <cj****@nova-tech.org> wrote in message
news:OQ**************@TK2MSFTNGP09.phx.gbl...
Cor,

Dohhhhhh, now I feel really stupid. Ok, I did adapted your sample to use the existing table. In the designer view the i and y are underlined, saying they are not declared and the "AS" is underlined in both cases (for i as
integer=0...), saying "syntax error".

I also did some search on google groups to find out more about the listbox
selected item. I tried:
Dim pickTry = pickBox.GetItemText(pickBox.SelectedItems)
but when I halt the program and check the value of pickTry it says the
object name and not the actual value.

Claus

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl...
Claus,

As I wrote in the sample, that is to create the sample datatable.
Thanks for the sample. I might not understand this right but I can't do the

Dim names() As String = New String() {"Geoff", "Cor", "Herfried", "Jay", "Herfried"}

because I don't know the usernames that are in the tbSelect table
until
I read them.


I assume you have somewhere your own datatable with usernames.

Cor


Nov 21 '05 #8

P: n/a
I found the property to set to MultiExtended. Still no luck with getting the
value of the selected items.

"cjobes" <cj****@nova-tech.org> wrote in message
news:ug**************@TK2MSFTNGP15.phx.gbl...
Cor,

I fixed that syntax error by declaring i and y before starting the routine
and taking the AS out of the code. It works very well and much faster than
before. Thanks.

I still can't get the selected value into a variable. The variable holds the Type instead of the actual value. I also can't select more than one value in the listbox. I have seen apps doing that so I know it's possible. I will do some further reseach on it.

Thanks again,
Claus
"cjobes" <cj****@nova-tech.org> wrote in message
news:OQ**************@TK2MSFTNGP09.phx.gbl...
Cor,

Dohhhhhh, now I feel really stupid. Ok, I did adapted your sample to use

the
existing table. In the designer view the i and y are underlined, saying

they
are not declared and the "AS" is underlined in both cases (for i as
integer=0...), saying "syntax error".

I also did some search on google groups to find out more about the listbox
selected item. I tried:
Dim pickTry = pickBox.GetItemText(pickBox.SelectedItems)
but when I halt the program and check the value of pickTry it says the
object name and not the actual value.

Claus

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl...
Claus,

As I wrote in the sample, that is to create the sample datatable.

> Thanks for the sample. I might not understand this right but I can't

do > the
>
> Dim names() As String = New String() {"Geoff", "Cor", "Herfried",

"Jay",
> "Herfried"}
>
> because I don't know the usernames that are in the tbSelect table

until
I
> read them.
>

I assume you have somewhere your own datatable with usernames.

Cor



Nov 21 '05 #9

P: n/a
I'm really stuck here. All my books say to get the value of a selected item
in a listbox you do something like this:
dim xValue=listbox1.selecteditem.tostring()
to test this I inserted:
messagebox.show("testing: "+listbox1.selecteditem.tostring())
what it displays is:
"Testing: System.Data.DataViewRow"

How can I get the actual value of the selected item?

Thanks,
Claus

"cjobes" <cj****@nova-tech.org> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I found the property to set to MultiExtended. Still no luck with getting the value of the selected items.

"cjobes" <cj****@nova-tech.org> wrote in message
news:ug**************@TK2MSFTNGP15.phx.gbl...
Cor,

I fixed that syntax error by declaring i and y before starting the routine
and taking the AS out of the code. It works very well and much faster than before. Thanks.

I still can't get the selected value into a variable. The variable holds the
Type instead of the actual value. I also can't select more than one value in
the listbox. I have seen apps doing that so I know it's possible. I will

do
some further reseach on it.

Thanks again,
Claus
"cjobes" <cj****@nova-tech.org> wrote in message
news:OQ**************@TK2MSFTNGP09.phx.gbl...
Cor,

Dohhhhhh, now I feel really stupid. Ok, I did adapted your sample to

use the
existing table. In the designer view the i and y are underlined,
saying they
are not declared and the "AS" is underlined in both cases (for i as
integer=0...), saying "syntax error".

I also did some search on google groups to find out more about the listbox selected item. I tried:
Dim pickTry = pickBox.GetItemText(pickBox.SelectedItems)
but when I halt the program and check the value of pickTry it says the
object name and not the actual value.

Claus

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl...
> Claus,
>
> As I wrote in the sample, that is to create the sample datatable.
>
> > Thanks for the sample. I might not understand this right but I

can't do
> > the
> >
> > Dim names() As String = New String() {"Geoff", "Cor", "Herfried",
"Jay",
> > "Herfried"}
> >
> > because I don't know the usernames that are in the tbSelect table

until
I
> > read them.
> >
>
> I assume you have somewhere your own datatable with usernames.
>
> Cor
>
>



Nov 21 '05 #10

P: n/a
You have to set the DisplayMember property of the ListBox to the name of the
Field from which it gets its data.

If you are using MultiExtended, to allow multiple selections of items, you
capture the selected items with:
Dim soc As ListBox.SelectedObjectCollection = ListBox1.SelectedItems

The collection items are ListViewItems, so loop through the collection:
dim lvi as listviewitem
dim s as string
For Each lvi in soc
s = lvi(0)
Next

If you are using a Value field to represent a Key for the UserID, that field
would be assigned to the ValueMember field of the ListBox.
"cjobes" wrote:
I'm really stuck here. All my books say to get the value of a selected item
in a listbox you do something like this:
dim xValue=listbox1.selecteditem.tostring()
to test this I inserted:
messagebox.show("testing: "+listbox1.selecteditem.tostring())
what it displays is:
"Testing: System.Data.DataViewRow"

How can I get the actual value of the selected item?

Thanks,
Claus

"cjobes" <cj****@nova-tech.org> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I found the property to set to MultiExtended. Still no luck with getting

the
value of the selected items.

"cjobes" <cj****@nova-tech.org> wrote in message
news:ug**************@TK2MSFTNGP15.phx.gbl...
Cor,

I fixed that syntax error by declaring i and y before starting the routine and taking the AS out of the code. It works very well and much faster than before. Thanks.

I still can't get the selected value into a variable. The variable holds

the
Type instead of the actual value. I also can't select more than one value
in
the listbox. I have seen apps doing that so I know it's possible. I will

do
some further reseach on it.

Thanks again,
Claus
"cjobes" <cj****@nova-tech.org> wrote in message
news:OQ**************@TK2MSFTNGP09.phx.gbl...
> Cor,
>
> Dohhhhhh, now I feel really stupid. Ok, I did adapted your sample to

use the
> existing table. In the designer view the i and y are underlined, saying they
> are not declared and the "AS" is underlined in both cases (for i as
> integer=0...), saying "syntax error".
>
> I also did some search on google groups to find out more about the

listbox
> selected item. I tried:
> Dim pickTry = pickBox.GetItemText(pickBox.SelectedItems)
> but when I halt the program and check the value of pickTry it says the
> object name and not the actual value.
>
> Claus
>
> "Cor Ligthert" <no************@planet.nl> wrote in message
> news:uH**************@TK2MSFTNGP09.phx.gbl...
> > Claus,
> >
> > As I wrote in the sample, that is to create the sample datatable.
> >
> > > Thanks for the sample. I might not understand this right but I can't do
> > > the
> > >
> > > Dim names() As String = New String() {"Geoff", "Cor", "Herfried",
> "Jay",
> > > "Herfried"}
> > >
> > > because I don't know the usernames that are in the tbSelect table
until
> I
> > > read them.
> > >
> >
> > I assume you have somewhere your own datatable with usernames.
> >
> > Cor
> >
> >
>
>



Nov 21 '05 #11

P: n/a
Just In Case

If you are using Option Strict
Make this change from the previous post:
For Each lvi in soc
s = lvi(0).tostring
Next

You can also reference any field from the datasource. Here's a snippet of
code to illustrate:

(in Load event)

Dim dt As New DataTable()
Dim dc0 As New DataColumn("UserID",
System.Type.GetType("System.Int32"))
Dim dc1 As New DataColumn("UserName",
System.Type.GetType("System.String"))
Dim dc2 As New DataColumn("StartDate",
System.Type.GetType("System.DateTime"))

dt.Columns.Add(dc0)
dt.Columns.Add(dc1)
dt.Columns.Add(dc2)

Dim dr As DataRow = dt.NewRow
dr.Item(0) = 1
dr.Item(1) = "Bob"
dr.Item(2) = #3/4/1999#
dt.Rows.Add(dr)

dr = dt.NewRow
dr.Item(0) = 2
dr.Item(1) = "Sam"
dr.Item(2) = #3/9/2004#
dt.Rows.Add(dr)
Me.ListBox1.DisplayMember = "UserName"
Me.ListBox1.DataSource = dt

(in button click event)

Dim soc As Windows.Forms.ListBox.SelectedObjectCollection =
ListBox1.SelectedItems
Dim drv As DataRowView
For Each drv In soc
Dim id As Int32 = drv(0)
Dim user As String = drv(1)
Dim d As Date = drv(2)
Next

"cjobes" wrote:
I'm really stuck here. All my books say to get the value of a selected item
in a listbox you do something like this:
dim xValue=listbox1.selecteditem.tostring()
to test this I inserted:
messagebox.show("testing: "+listbox1.selecteditem.tostring())
what it displays is:
"Testing: System.Data.DataViewRow"

How can I get the actual value of the selected item?

Thanks,
Claus

"cjobes" <cj****@nova-tech.org> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I found the property to set to MultiExtended. Still no luck with getting

the
value of the selected items.

"cjobes" <cj****@nova-tech.org> wrote in message
news:ug**************@TK2MSFTNGP15.phx.gbl...
Cor,

I fixed that syntax error by declaring i and y before starting the routine and taking the AS out of the code. It works very well and much faster than before. Thanks.

I still can't get the selected value into a variable. The variable holds

the
Type instead of the actual value. I also can't select more than one value
in
the listbox. I have seen apps doing that so I know it's possible. I will

do
some further reseach on it.

Thanks again,
Claus
"cjobes" <cj****@nova-tech.org> wrote in message
news:OQ**************@TK2MSFTNGP09.phx.gbl...
> Cor,
>
> Dohhhhhh, now I feel really stupid. Ok, I did adapted your sample to

use the
> existing table. In the designer view the i and y are underlined, saying they
> are not declared and the "AS" is underlined in both cases (for i as
> integer=0...), saying "syntax error".
>
> I also did some search on google groups to find out more about the

listbox
> selected item. I tried:
> Dim pickTry = pickBox.GetItemText(pickBox.SelectedItems)
> but when I halt the program and check the value of pickTry it says the
> object name and not the actual value.
>
> Claus
>
> "Cor Ligthert" <no************@planet.nl> wrote in message
> news:uH**************@TK2MSFTNGP09.phx.gbl...
> > Claus,
> >
> > As I wrote in the sample, that is to create the sample datatable.
> >
> > > Thanks for the sample. I might not understand this right but I can't do
> > > the
> > >
> > > Dim names() As String = New String() {"Geoff", "Cor", "Herfried",
> "Jay",
> > > "Herfried"}
> > >
> > > because I don't know the usernames that are in the tbSelect table
until
> I
> > > read them.
> > >
> >
> > I assume you have somewhere your own datatable with usernames.
> >
> > Cor
> >
> >
>
>



Nov 21 '05 #12

P: n/a
Correction: The SelectedObjectCollection contains DataRowView objects, not
ListViewItem objects as I stated in my first post on this thread. Sorry.
(That's what can happen when code is not checked out first.)

First post erroneous code:

Dim soc As Windows.Forms.ListBox.SelectedObjectCollection =
ListBox1.SelectedItems
dim lvi as listviewitem
dim s as string
For Each lvi in soc
s = lvi(0)
Next

The second post has it right:

(see post for datasource setup)
Dim soc As Windows.Forms.ListBox.SelectedObjectCollection =
ListBox1.SelectedItems
Dim drv As DataRowView
For Each drv In soc
Dim id As Int32 = drv(0)
Dim user As String = drv(1)
Dim d As Date = drv(2)
Next

Though I would even change the correct code, and put the Dim statements
outside the loop.

Charlie

"cjobes" wrote:
I'm really stuck here. All my books say to get the value of a selected item
in a listbox you do something like this:
dim xValue=listbox1.selecteditem.tostring()
to test this I inserted:
messagebox.show("testing: "+listbox1.selecteditem.tostring())
what it displays is:
"Testing: System.Data.DataViewRow"

How can I get the actual value of the selected item?

Thanks,
Claus

"cjobes" <cj****@nova-tech.org> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I found the property to set to MultiExtended. Still no luck with getting

the
value of the selected items.

"cjobes" <cj****@nova-tech.org> wrote in message
news:ug**************@TK2MSFTNGP15.phx.gbl...
Cor,

I fixed that syntax error by declaring i and y before starting the routine and taking the AS out of the code. It works very well and much faster than before. Thanks.

I still can't get the selected value into a variable. The variable holds

the
Type instead of the actual value. I also can't select more than one value
in
the listbox. I have seen apps doing that so I know it's possible. I will

do
some further reseach on it.

Thanks again,
Claus
"cjobes" <cj****@nova-tech.org> wrote in message
news:OQ**************@TK2MSFTNGP09.phx.gbl...
> Cor,
>
> Dohhhhhh, now I feel really stupid. Ok, I did adapted your sample to

use the
> existing table. In the designer view the i and y are underlined, saying they
> are not declared and the "AS" is underlined in both cases (for i as
> integer=0...), saying "syntax error".
>
> I also did some search on google groups to find out more about the

listbox
> selected item. I tried:
> Dim pickTry = pickBox.GetItemText(pickBox.SelectedItems)
> but when I halt the program and check the value of pickTry it says the
> object name and not the actual value.
>
> Claus
>
> "Cor Ligthert" <no************@planet.nl> wrote in message
> news:uH**************@TK2MSFTNGP09.phx.gbl...
> > Claus,
> >
> > As I wrote in the sample, that is to create the sample datatable.
> >
> > > Thanks for the sample. I might not understand this right but I can't do
> > > the
> > >
> > > Dim names() As String = New String() {"Geoff", "Cor", "Herfried",
> "Jay",
> > > "Herfried"}
> > >
> > > because I don't know the usernames that are in the tbSelect table
until
> I
> > > read them.
> > >
> >
> > I assume you have somewhere your own datatable with usernames.
> >
> > Cor
> >
> >
>
>



Nov 21 '05 #13

P: n/a
Thanks Charlie,

I'm currently on the road and will try this tonight.

Claus

"Charlie" <cfarrier at charlesfarriersoftware.com> wrote in message
news:A0**********************************@microsof t.com...
Correction: The SelectedObjectCollection contains DataRowView objects, not ListViewItem objects as I stated in my first post on this thread. Sorry.
(That's what can happen when code is not checked out first.)

First post erroneous code:

Dim soc As Windows.Forms.ListBox.SelectedObjectCollection =
ListBox1.SelectedItems
dim lvi as listviewitem
dim s as string
For Each lvi in soc
s = lvi(0)
Next

The second post has it right:

(see post for datasource setup)
Dim soc As Windows.Forms.ListBox.SelectedObjectCollection =
ListBox1.SelectedItems
Dim drv As DataRowView
For Each drv In soc
Dim id As Int32 = drv(0)
Dim user As String = drv(1)
Dim d As Date = drv(2)
Next

Though I would even change the correct code, and put the Dim statements
outside the loop.

Charlie

"cjobes" wrote:
I'm really stuck here. All my books say to get the value of a selected item in a listbox you do something like this:
dim xValue=listbox1.selecteditem.tostring()
to test this I inserted:
messagebox.show("testing: "+listbox1.selecteditem.tostring())
what it displays is:
"Testing: System.Data.DataViewRow"

How can I get the actual value of the selected item?

Thanks,
Claus

"cjobes" <cj****@nova-tech.org> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I found the property to set to MultiExtended. Still no luck with getting
the
value of the selected items.

"cjobes" <cj****@nova-tech.org> wrote in message
news:ug**************@TK2MSFTNGP15.phx.gbl...
> Cor,
>
> I fixed that syntax error by declaring i and y before starting the

routine
> and taking the AS out of the code. It works very well and much
faster than
> before. Thanks.
>
> I still can't get the selected value into a variable. The variable
holds the
> Type instead of the actual value. I also can't select more than one

value
in
> the listbox. I have seen apps doing that so I know it's possible. I will do
> some further reseach on it.
>
> Thanks again,
> Claus
> "cjobes" <cj****@nova-tech.org> wrote in message
> news:OQ**************@TK2MSFTNGP09.phx.gbl...
> > Cor,
> >
> > Dohhhhhh, now I feel really stupid. Ok, I did adapted your sample to use
> the
> > existing table. In the designer view the i and y are underlined,

saying
> they
> > are not declared and the "AS" is underlined in both cases (for i

as > > integer=0...), saying "syntax error".
> >
> > I also did some search on google groups to find out more about the
listbox
> > selected item. I tried:
> > Dim pickTry = pickBox.GetItemText(pickBox.SelectedItems)
> > but when I halt the program and check the value of pickTry it says the > > object name and not the actual value.
> >
> > Claus
> >
> > "Cor Ligthert" <no************@planet.nl> wrote in message
> > news:uH**************@TK2MSFTNGP09.phx.gbl...
> > > Claus,
> > >
> > > As I wrote in the sample, that is to create the sample datatable. > > >
> > > > Thanks for the sample. I might not understand this right but I

can't
> do
> > > > the
> > > >
> > > > Dim names() As String = New String() {"Geoff", "Cor", "Herfried", > > "Jay",
> > > > "Herfried"}
> > > >
> > > > because I don't know the usernames that are in the tbSelect table > until
> > I
> > > > read them.
> > > >
> > >
> > > I assume you have somewhere your own datatable with usernames.
> > >
> > > Cor
> > >
> > >
> >
> >
>
>


Nov 21 '05 #14

P: n/a
Thanks Charlie,

As always, it works like a charme. I wish there was better documentation
around so I would not have to bother you so often. I have 3 books that are
supposed to be really good but more often than I would like, they don't have
the answers. I wish there was a book out that had a windows forms project
with all the code and then takes the reader through it by example.

Claus

"Charlie" <cfarrier at charlesfarriersoftware.com> wrote in message
news:A0**********************************@microsof t.com...
Correction: The SelectedObjectCollection contains DataRowView objects, not ListViewItem objects as I stated in my first post on this thread. Sorry.
(That's what can happen when code is not checked out first.)

First post erroneous code:

Dim soc As Windows.Forms.ListBox.SelectedObjectCollection =
ListBox1.SelectedItems
dim lvi as listviewitem
dim s as string
For Each lvi in soc
s = lvi(0)
Next

The second post has it right:

(see post for datasource setup)
Dim soc As Windows.Forms.ListBox.SelectedObjectCollection =
ListBox1.SelectedItems
Dim drv As DataRowView
For Each drv In soc
Dim id As Int32 = drv(0)
Dim user As String = drv(1)
Dim d As Date = drv(2)
Next

Though I would even change the correct code, and put the Dim statements
outside the loop.

Charlie

"cjobes" wrote:
I'm really stuck here. All my books say to get the value of a selected item in a listbox you do something like this:
dim xValue=listbox1.selecteditem.tostring()
to test this I inserted:
messagebox.show("testing: "+listbox1.selecteditem.tostring())
what it displays is:
"Testing: System.Data.DataViewRow"

How can I get the actual value of the selected item?

Thanks,
Claus

"cjobes" <cj****@nova-tech.org> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I found the property to set to MultiExtended. Still no luck with getting
the
value of the selected items.

"cjobes" <cj****@nova-tech.org> wrote in message
news:ug**************@TK2MSFTNGP15.phx.gbl...
> Cor,
>
> I fixed that syntax error by declaring i and y before starting the

routine
> and taking the AS out of the code. It works very well and much
faster than
> before. Thanks.
>
> I still can't get the selected value into a variable. The variable
holds the
> Type instead of the actual value. I also can't select more than one

value
in
> the listbox. I have seen apps doing that so I know it's possible. I will do
> some further reseach on it.
>
> Thanks again,
> Claus
> "cjobes" <cj****@nova-tech.org> wrote in message
> news:OQ**************@TK2MSFTNGP09.phx.gbl...
> > Cor,
> >
> > Dohhhhhh, now I feel really stupid. Ok, I did adapted your sample to use
> the
> > existing table. In the designer view the i and y are underlined,

saying
> they
> > are not declared and the "AS" is underlined in both cases (for i

as > > integer=0...), saying "syntax error".
> >
> > I also did some search on google groups to find out more about the
listbox
> > selected item. I tried:
> > Dim pickTry = pickBox.GetItemText(pickBox.SelectedItems)
> > but when I halt the program and check the value of pickTry it says the > > object name and not the actual value.
> >
> > Claus
> >
> > "Cor Ligthert" <no************@planet.nl> wrote in message
> > news:uH**************@TK2MSFTNGP09.phx.gbl...
> > > Claus,
> > >
> > > As I wrote in the sample, that is to create the sample datatable. > > >
> > > > Thanks for the sample. I might not understand this right but I

can't
> do
> > > > the
> > > >
> > > > Dim names() As String = New String() {"Geoff", "Cor", "Herfried", > > "Jay",
> > > > "Herfried"}
> > > >
> > > > because I don't know the usernames that are in the tbSelect table > until
> > I
> > > > read them.
> > > >
> > >
> > > I assume you have somewhere your own datatable with usernames.
> > >
> > > Cor
> > >
> > >
> >
> >
>
>


Nov 21 '05 #15

P: n/a
Thanks for letting me know. I agree. Learning by example is very effective.
The first book I used was full of mistakes. Once I realized that, the book
became like "Where's Waldo?". In some way, it was helpful, because it made
me more of a detective. But I sure do like how VB helps the programmer nail
errors, and how intellisense provides a list of members, even for derived
classes. I think that is what made VB the most used language in the world.

I sent you an e-mail at your web address.

"cjobes" wrote:
Thanks Charlie,

As always, it works like a charme. I wish there was better documentation
around so I would not have to bother you so often. I have 3 books that are
supposed to be really good but more often than I would like, they don't have
the answers. I wish there was a book out that had a windows forms project
with all the code and then takes the reader through it by example.

Claus

"Charlie" <cfarrier at charlesfarriersoftware.com> wrote in message
news:A0**********************************@microsof t.com...
Correction: The SelectedObjectCollection contains DataRowView objects,

not
ListViewItem objects as I stated in my first post on this thread. Sorry.
(That's what can happen when code is not checked out first.)

First post erroneous code:

Dim soc As Windows.Forms.ListBox.SelectedObjectCollection =
ListBox1.SelectedItems
dim lvi as listviewitem
dim s as string
For Each lvi in soc
s = lvi(0)
Next

The second post has it right:

(see post for datasource setup)
Dim soc As Windows.Forms.ListBox.SelectedObjectCollection =
ListBox1.SelectedItems
Dim drv As DataRowView
For Each drv In soc
Dim id As Int32 = drv(0)
Dim user As String = drv(1)
Dim d As Date = drv(2)
Next

Though I would even change the correct code, and put the Dim statements
outside the loop.

Charlie

"cjobes" wrote:
I'm really stuck here. All my books say to get the value of a selected item in a listbox you do something like this:
dim xValue=listbox1.selecteditem.tostring()
to test this I inserted:
messagebox.show("testing: "+listbox1.selecteditem.tostring())
what it displays is:
"Testing: System.Data.DataViewRow"

How can I get the actual value of the selected item?

Thanks,
Claus

"cjobes" <cj****@nova-tech.org> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
> I found the property to set to MultiExtended. Still no luck with getting the
> value of the selected items.
>
> "cjobes" <cj****@nova-tech.org> wrote in message
> news:ug**************@TK2MSFTNGP15.phx.gbl...
> > Cor,
> >
> > I fixed that syntax error by declaring i and y before starting the
routine
> > and taking the AS out of the code. It works very well and much faster than
> > before. Thanks.
> >
> > I still can't get the selected value into a variable. The variable holds > the
> > Type instead of the actual value. I also can't select more than one
value
> in
> > the listbox. I have seen apps doing that so I know it's possible. I will > do
> > some further reseach on it.
> >
> > Thanks again,
> > Claus
> > "cjobes" <cj****@nova-tech.org> wrote in message
> > news:OQ**************@TK2MSFTNGP09.phx.gbl...
> > > Cor,
> > >
> > > Dohhhhhh, now I feel really stupid. Ok, I did adapted your sample to use
> > the
> > > existing table. In the designer view the i and y are underlined,
saying
> > they
> > > are not declared and the "AS" is underlined in both cases (for i as > > > integer=0...), saying "syntax error".
> > >
> > > I also did some search on google groups to find out more about the
> listbox
> > > selected item. I tried:
> > > Dim pickTry = pickBox.GetItemText(pickBox.SelectedItems)
> > > but when I halt the program and check the value of pickTry it says the > > > object name and not the actual value.
> > >
> > > Claus
> > >
> > > "Cor Ligthert" <no************@planet.nl> wrote in message
> > > news:uH**************@TK2MSFTNGP09.phx.gbl...
> > > > Claus,
> > > >
> > > > As I wrote in the sample, that is to create the sample datatable. > > > >
> > > > > Thanks for the sample. I might not understand this right but I
can't
> > do
> > > > > the
> > > > >
> > > > > Dim names() As String = New String() {"Geoff", "Cor", "Herfried", > > > "Jay",
> > > > > "Herfried"}
> > > > >
> > > > > because I don't know the usernames that are in the tbSelect table > > until
> > > I
> > > > > read them.
> > > > >
> > > >
> > > > I assume you have somewhere your own datatable with usernames.
> > > >
> > > > Cor
> > > >
> > > >
> > >
> > >
> >
> >
>
>


Nov 21 '05 #16

P: n/a
Claus,

Next time show how you have setted the displaymember, mostly it has to do
with a case sensitive situation. This part is case sesitive.

We live in another time segment of the world which means that there can be
big time gabs.

However I hope this helps?

Cor
Nov 21 '05 #17

P: n/a
Cor,

Here is the code that does the job including preparing the search string:

Dim pickTry As String = ""
Dim soc As Windows.Forms.ListBox.SelectedObjectCollection = _
pickBox.SelectedItems()
Dim drv As DataRowView
For Each drv In soc
If Len(pickTry) < 1 Then
pickTry = "user='" + drv(0) + "'"
Else
pickTry = pickTry + " or user='" + drv(0) + "'"
End If
Next

Thanks again for your help. I'm slowly getting a hang of it.

Claus
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Claus,

Next time show how you have setted the displaymember, mostly it has to do
with a case sensitive situation. This part is case sesitive.

We live in another time segment of the world which means that there can be
big time gabs.

However I hope this helps?

Cor

Nov 21 '05 #18

P: n/a
Claus,

You can do something as this (when you have not set multiselect to true)
Dim picktry As String = DirectCast(ListBox1.SelectedItem,
DataRowView).Item(0).ToString

What you can do as well is setting the datavalue of your listbox to the
"user" as well, that is the same as your displaymember (so both the same),
than it becomes
Dim picktry As String = ListBox1.SelectedValue.ToString

I hope this helps?

Cor

"cjobes" <cj****@nova-tech.org>

Cor,

Here is the code that does the job including preparing the search string:

Dim pickTry As String = ""
Dim soc As Windows.Forms.ListBox.SelectedObjectCollection = _
pickBox.SelectedItems()
Dim drv As DataRowView
For Each drv In soc
If Len(pickTry) < 1 Then
pickTry = "user='" + drv(0) + "'"
Else
pickTry = pickTry + " or user='" + drv(0) + "'"
End If
Next

Thanks again for your help. I'm slowly getting a hang of it.

Claus
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Claus,

Next time show how you have setted the displaymember, mostly it has to do
with a case sensitive situation. This part is case sesitive.

We live in another time segment of the world which means that there can
be
big time gabs.

However I hope this helps?

Cor


Nov 21 '05 #19

P: n/a
Cor,

Thanks, in this case multiselect is true. That's why I had to do the loop.

Claus
"Cor Ligthert" <no************@planet.nl> wrote in message
news:uU****************@tk2msftngp13.phx.gbl...
Claus,

You can do something as this (when you have not set multiselect to true)
Dim picktry As String = DirectCast(ListBox1.SelectedItem,
DataRowView).Item(0).ToString

What you can do as well is setting the datavalue of your listbox to the
"user" as well, that is the same as your displaymember (so both the same),
than it becomes
Dim picktry As String = ListBox1.SelectedValue.ToString

I hope this helps?

Cor

"cjobes" <cj****@nova-tech.org>

Cor,

Here is the code that does the job including preparing the search string:
Dim pickTry As String = ""
Dim soc As Windows.Forms.ListBox.SelectedObjectCollection = _
pickBox.SelectedItems()
Dim drv As DataRowView
For Each drv In soc
If Len(pickTry) < 1 Then
pickTry = "user='" + drv(0) + "'"
Else
pickTry = pickTry + " or user='" + drv(0) + "'"
End If
Next

Thanks again for your help. I'm slowly getting a hang of it.

Claus
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Claus,

Next time show how you have setted the displaymember, mostly it has to do with a case sensitive situation. This part is case sesitive.

We live in another time segment of the world which means that there can
be
big time gabs.

However I hope this helps?

Cor



Nov 21 '05 #20

P: n/a
Cor,

Thanks, in this case multiselect is true. That's why I had to do the loop.

Claus
"Cor Ligthert" <no************@planet.nl> wrote in message
news:uU****************@tk2msftngp13.phx.gbl...
Claus,

You can do something as this (when you have not set multiselect to true)
Dim picktry As String = DirectCast(ListBox1.SelectedItem,
DataRowView).Item(0).ToString

What you can do as well is setting the datavalue of your listbox to the
"user" as well, that is the same as your displaymember (so both the same),
than it becomes
Dim picktry As String = ListBox1.SelectedValue.ToString

I hope this helps?

Cor

"cjobes" <cj****@nova-tech.org>

Cor,

Here is the code that does the job including preparing the search string:
Dim pickTry As String = ""
Dim soc As Windows.Forms.ListBox.SelectedObjectCollection = _
pickBox.SelectedItems()
Dim drv As DataRowView
For Each drv In soc
If Len(pickTry) < 1 Then
pickTry = "user='" + drv(0) + "'"
Else
pickTry = pickTry + " or user='" + drv(0) + "'"
End If
Next

Thanks again for your help. I'm slowly getting a hang of it.

Claus
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Claus,

Next time show how you have setted the displaymember, mostly it has to do with a case sensitive situation. This part is case sesitive.

We live in another time segment of the world which means that there can
be
big time gabs.

However I hope this helps?

Cor



Nov 21 '05 #21

P: n/a
Claus,

Than you cannot set it in a single string as you did, however have to do
that to an array something as
\\\
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim myarray(ListBox1.SelectedItems.Count - 1) As String
For i As Integer = 0 To ListBox1.SelectedItems.Count - 1
myarray(i) = DirectCast(ListBox1.SelectedItems(i), _
DataRowView)(0).ToString
Next
End Sub
////

"cjobes" <cj****@nova-tech.org>
Cor,

Thanks, in this case multiselect is true. That's why I had to do the loop.

Claus
"Cor Ligthert" <no************@planet.nl> wrote in message
news:uU****************@tk2msftngp13.phx.gbl...
Claus,

You can do something as this (when you have not set multiselect to true)
Dim picktry As String = DirectCast(ListBox1.SelectedItem,
DataRowView).Item(0).ToString

What you can do as well is setting the datavalue of your listbox to the
"user" as well, that is the same as your displaymember (so both the
same),
than it becomes
Dim picktry As String = ListBox1.SelectedValue.ToString

I hope this helps?

Cor

"cjobes" <cj****@nova-tech.org>

> Cor,
>
> Here is the code that does the job including preparing the search string: >
> Dim pickTry As String = ""
> Dim soc As Windows.Forms.ListBox.SelectedObjectCollection = _
> pickBox.SelectedItems()
> Dim drv As DataRowView
> For Each drv In soc
> If Len(pickTry) < 1 Then
> pickTry = "user='" + drv(0) + "'"
> Else
> pickTry = pickTry + " or user='" + drv(0) + "'"
> End If
> Next
>
> Thanks again for your help. I'm slowly getting a hang of it.
>
> Claus
> "Cor Ligthert" <no************@planet.nl> wrote in message
> news:%2***************@TK2MSFTNGP09.phx.gbl...
>> Claus,
>>
>> Next time show how you have setted the displaymember, mostly it has to do >> with a case sensitive situation. This part is case sesitive.
>>
>> We live in another time segment of the world which means that there
>> can
>> be
>> big time gabs.
>>
>> However I hope this helps?
>>
>> Cor
>>
>>
>
>



Nov 21 '05 #22

P: n/a
Claus,

Than you cannot set it in a single string as you did, however have to do
that to an array something as
\\\
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim myarray(ListBox1.SelectedItems.Count - 1) As String
For i As Integer = 0 To ListBox1.SelectedItems.Count - 1
myarray(i) = DirectCast(ListBox1.SelectedItems(i), _
DataRowView)(0).ToString
Next
End Sub
////

"cjobes" <cj****@nova-tech.org>
Cor,

Thanks, in this case multiselect is true. That's why I had to do the loop.

Claus
"Cor Ligthert" <no************@planet.nl> wrote in message
news:uU****************@tk2msftngp13.phx.gbl...
Claus,

You can do something as this (when you have not set multiselect to true)
Dim picktry As String = DirectCast(ListBox1.SelectedItem,
DataRowView).Item(0).ToString

What you can do as well is setting the datavalue of your listbox to the
"user" as well, that is the same as your displaymember (so both the
same),
than it becomes
Dim picktry As String = ListBox1.SelectedValue.ToString

I hope this helps?

Cor

"cjobes" <cj****@nova-tech.org>

> Cor,
>
> Here is the code that does the job including preparing the search string: >
> Dim pickTry As String = ""
> Dim soc As Windows.Forms.ListBox.SelectedObjectCollection = _
> pickBox.SelectedItems()
> Dim drv As DataRowView
> For Each drv In soc
> If Len(pickTry) < 1 Then
> pickTry = "user='" + drv(0) + "'"
> Else
> pickTry = pickTry + " or user='" + drv(0) + "'"
> End If
> Next
>
> Thanks again for your help. I'm slowly getting a hang of it.
>
> Claus
> "Cor Ligthert" <no************@planet.nl> wrote in message
> news:%2***************@TK2MSFTNGP09.phx.gbl...
>> Claus,
>>
>> Next time show how you have setted the displaymember, mostly it has to do >> with a case sensitive situation. This part is case sesitive.
>>
>> We live in another time segment of the world which means that there
>> can
>> be
>> big time gabs.
>>
>> However I hope this helps?
>>
>> Cor
>>
>>
>
>



Nov 21 '05 #23

P: n/a
Cor,

The code that I posted works great. It creates the search string and the
selection comes up in the grid.

Claus

"Cor Ligthert" <no************@planet.nl> wrote in message
news:eH**************@TK2MSFTNGP10.phx.gbl...
Claus,

Than you cannot set it in a single string as you did, however have to do
that to an array something as
\\\
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim myarray(ListBox1.SelectedItems.Count - 1) As String
For i As Integer = 0 To ListBox1.SelectedItems.Count - 1
myarray(i) = DirectCast(ListBox1.SelectedItems(i), _
DataRowView)(0).ToString
Next
End Sub
////

"cjobes" <cj****@nova-tech.org>
Cor,

Thanks, in this case multiselect is true. That's why I had to do the loop.
Claus
"Cor Ligthert" <no************@planet.nl> wrote in message
news:uU****************@tk2msftngp13.phx.gbl...
Claus,

You can do something as this (when you have not set multiselect to true) Dim picktry As String = DirectCast(ListBox1.SelectedItem,
DataRowView).Item(0).ToString

What you can do as well is setting the datavalue of your listbox to the
"user" as well, that is the same as your displaymember (so both the
same),
than it becomes
Dim picktry As String = ListBox1.SelectedValue.ToString

I hope this helps?

Cor

"cjobes" <cj****@nova-tech.org>
> Cor,
>
> Here is the code that does the job including preparing the search

string:
>
> Dim pickTry As String = ""
> Dim soc As Windows.Forms.ListBox.SelectedObjectCollection = _
> pickBox.SelectedItems()
> Dim drv As DataRowView
> For Each drv In soc
> If Len(pickTry) < 1 Then
> pickTry = "user='" + drv(0) + "'"
> Else
> pickTry = pickTry + " or user='" + drv(0) + "'"
> End If
> Next
>
> Thanks again for your help. I'm slowly getting a hang of it.
>
> Claus
> "Cor Ligthert" <no************@planet.nl> wrote in message
> news:%2***************@TK2MSFTNGP09.phx.gbl...
>> Claus,
>>
>> Next time show how you have setted the displaymember, mostly it has
to do
>> with a case sensitive situation. This part is case sesitive.
>>
>> We live in another time segment of the world which means that there
>> can
>> be
>> big time gabs.
>>
>> However I hope this helps?
>>
>> Cor
>>
>>
>
>



Nov 21 '05 #24

P: n/a
Cor,

The code that I posted works great. It creates the search string and the
selection comes up in the grid.

Claus

"Cor Ligthert" <no************@planet.nl> wrote in message
news:eH**************@TK2MSFTNGP10.phx.gbl...
Claus,

Than you cannot set it in a single string as you did, however have to do
that to an array something as
\\\
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim myarray(ListBox1.SelectedItems.Count - 1) As String
For i As Integer = 0 To ListBox1.SelectedItems.Count - 1
myarray(i) = DirectCast(ListBox1.SelectedItems(i), _
DataRowView)(0).ToString
Next
End Sub
////

"cjobes" <cj****@nova-tech.org>
Cor,

Thanks, in this case multiselect is true. That's why I had to do the loop.
Claus
"Cor Ligthert" <no************@planet.nl> wrote in message
news:uU****************@tk2msftngp13.phx.gbl...
Claus,

You can do something as this (when you have not set multiselect to true) Dim picktry As String = DirectCast(ListBox1.SelectedItem,
DataRowView).Item(0).ToString

What you can do as well is setting the datavalue of your listbox to the
"user" as well, that is the same as your displaymember (so both the
same),
than it becomes
Dim picktry As String = ListBox1.SelectedValue.ToString

I hope this helps?

Cor

"cjobes" <cj****@nova-tech.org>
> Cor,
>
> Here is the code that does the job including preparing the search

string:
>
> Dim pickTry As String = ""
> Dim soc As Windows.Forms.ListBox.SelectedObjectCollection = _
> pickBox.SelectedItems()
> Dim drv As DataRowView
> For Each drv In soc
> If Len(pickTry) < 1 Then
> pickTry = "user='" + drv(0) + "'"
> Else
> pickTry = pickTry + " or user='" + drv(0) + "'"
> End If
> Next
>
> Thanks again for your help. I'm slowly getting a hang of it.
>
> Claus
> "Cor Ligthert" <no************@planet.nl> wrote in message
> news:%2***************@TK2MSFTNGP09.phx.gbl...
>> Claus,
>>
>> Next time show how you have setted the displaymember, mostly it has
to do
>> with a case sensitive situation. This part is case sesitive.
>>
>> We live in another time segment of the world which means that there
>> can
>> be
>> big time gabs.
>>
>> However I hope this helps?
>>
>> Cor
>>
>>
>
>



Nov 21 '05 #25

P: n/a
Claus,

I was not sure of that, however now I look to it I see what you are up too.
I advise you to try some simple changes.

Dim pickTry As String = ""
Dim drv As DataRowView
For Each drv In pickBox.SelectedItems
If pickTry = "" Then
pickTry = "user='" & drv(0) & "'"
Else
pickTry = pickTry & " or user='" & drv(0) & "'"
End If
Next

The first changes because it does the same and is more standard, the change
from + in & because using the + can give in VBNet give problems. (Not in
this case by the way, however using it standard is not confusing)

Cor
Nov 21 '05 #26

P: n/a
Claus,

I was not sure of that, however now I look to it I see what you are up too.
I advise you to try some simple changes.

Dim pickTry As String = ""
Dim drv As DataRowView
For Each drv In pickBox.SelectedItems
If pickTry = "" Then
pickTry = "user='" & drv(0) & "'"
Else
pickTry = pickTry & " or user='" & drv(0) & "'"
End If
Next

The first changes because it does the same and is more standard, the change
from + in & because using the + can give in VBNet give problems. (Not in
this case by the way, however using it standard is not confusing)

Cor
Nov 21 '05 #27

P: n/a
Thanks Cor,

Standard is always good and your advice fixed another problem in a different
project where the + didn't seem to work.

Claus
"Cor Ligthert" <no************@planet.nl> wrote in message
news:uv*************@TK2MSFTNGP12.phx.gbl...
Claus,

I was not sure of that, however now I look to it I see what you are up too. I advise you to try some simple changes.

Dim pickTry As String = ""
Dim drv As DataRowView
For Each drv In pickBox.SelectedItems
If pickTry = "" Then
pickTry = "user='" & drv(0) & "'"
Else
pickTry = pickTry & " or user='" & drv(0) & "'"
End If
Next

The first changes because it does the same and is more standard, the change from + in & because using the + can give in VBNet give problems. (Not in
this case by the way, however using it standard is not confusing)

Cor

Nov 21 '05 #28

P: n/a
Thanks Cor,

Standard is always good and your advice fixed another problem in a different
project where the + didn't seem to work.

Claus
"Cor Ligthert" <no************@planet.nl> wrote in message
news:uv*************@TK2MSFTNGP12.phx.gbl...
Claus,

I was not sure of that, however now I look to it I see what you are up too. I advise you to try some simple changes.

Dim pickTry As String = ""
Dim drv As DataRowView
For Each drv In pickBox.SelectedItems
If pickTry = "" Then
pickTry = "user='" & drv(0) & "'"
Else
pickTry = pickTry & " or user='" & drv(0) & "'"
End If
Next

The first changes because it does the same and is more standard, the change from + in & because using the + can give in VBNet give problems. (Not in
this case by the way, however using it standard is not confusing)

Cor

Nov 21 '05 #29

This discussion thread is closed

Replies have been disabled for this discussion.