PC Review


Reply
Thread Tools Rate Thread

Re: ListBox / Way 2 insert at entry index 0 while bound ?

 
 
Thomas Robertson
Guest
Posts: n/a
 
      26th Aug 2003
What exception do you get? I am using the below code and it works
fine...

' load the ProductList listbox
If Not (lbProductList Is Nothing) Then
lbProductList.DataSource = oStoreData.Products.GetProductQNav()
lbProductList.DataTextField = "name"
lbProductList.DataValueField = "code"
lbProductList.DataBind()
lbProductList.Items.Insert(0, "Product List")
lbProductList.Items(0).Value = "-"
lbProductList.Items.Insert(0, "-Select Product To View-")
lbProductList.Items(0).Value = ""
End If

Maybe it is when you are binding it? I bind then do whatever else I have
to do afterwards. Have you stepped through it and found when it is bombing
out on you? If that didn't help figure out where it is failing and post the
code. I am sure someone can figure it out.

HTH,

Tom

"One Handed Man" <terry_burnsREMOVE%FOR%NO%(E-Mail Removed)> wrote in
message news:eaDYZQ%(E-Mail Removed)...
> Scenario
> ---------
> Usng a data bound listbox to a table containing sorted data. ListBox has
> sorted turned off so takes sorted data straight from the table.
> Problem
> ---------
> Want to be able to insert an item at start of list before sorted items

from
> table.
>
> 1.) cannot use listbox insert method when lb is databound because it

throws
> a runtime exception
> 2.) tried to insertAt( Object, 0 ) // at first position, but it allways

goes
> to the end.
>
> So . . .
>
> Why is 2.) Happening and any ideas for coding around this problem ?
>
> Any help is appreciated
>
>
>
>
> --
> Regards - One Handed Man
>
> Author : Fish .NET & Keep .NET
>
> ==============================
>
>



 
Reply With Quote
 
 
 
 
One Handed Man
Guest
Posts: n/a
 
      26th Aug 2003
I set the binding up at design time. It builds without error, but refuses to
allow the insert because the control is bound to a data source.



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim NR As DataRow = Ds1.Tables("People").NewRow

Dim t As DataTable = Ds1.Tables("People")

NR("FirstName") = "All Items"

Ds1.Tables("People").Rows.InsertAt(NR, 0) <<<<<< ERROR Cannot insert when
data source is selected

End Sub


--
Regards - One Handed Man

Author : Fish .NET & Keep .NET

==============================
"Thomas Robertson" <(E-Mail Removed)> wrote in message
news:%23puAlh$(E-Mail Removed)...
> What exception do you get? I am using the below code and it works
> fine...
>
> ' load the ProductList listbox
> If Not (lbProductList Is Nothing) Then
> lbProductList.DataSource = oStoreData.Products.GetProductQNav()
> lbProductList.DataTextField = "name"
> lbProductList.DataValueField = "code"
> lbProductList.DataBind()
> lbProductList.Items.Insert(0, "Product List")
> lbProductList.Items(0).Value = "-"
> lbProductList.Items.Insert(0, "-Select Product To View-")
> lbProductList.Items(0).Value = ""
> End If
>
> Maybe it is when you are binding it? I bind then do whatever else I

have
> to do afterwards. Have you stepped through it and found when it is bombing
> out on you? If that didn't help figure out where it is failing and post

the
> code. I am sure someone can figure it out.
>
> HTH,
>
> Tom
>
> "One Handed Man" <terry_burnsREMOVE%FOR%NO%(E-Mail Removed)> wrote in
> message news:eaDYZQ%(E-Mail Removed)...
> > Scenario
> > ---------
> > Usng a data bound listbox to a table containing sorted data. ListBox has
> > sorted turned off so takes sorted data straight from the table.
> > Problem
> > ---------
> > Want to be able to insert an item at start of list before sorted items

> from
> > table.
> >
> > 1.) cannot use listbox insert method when lb is databound because it

> throws
> > a runtime exception
> > 2.) tried to insertAt( Object, 0 ) // at first position, but it allways

> goes
> > to the end.
> >
> > So . . .
> >
> > Why is 2.) Happening and any ideas for coding around this problem ?
> >
> > Any help is appreciated
> >
> >
> >
> >
> > --
> > Regards - One Handed Man
> >
> > Author : Fish .NET & Keep .NET
> >
> > ==============================
> >
> >

>
>



 
Reply With Quote
 
Anton Sommer
Guest
Posts: n/a
 
      4th Sep 2003


call this for your listbox even after databind, but don't insert if into
your source table

Listbox.Items.Insert(0, New ListItem("keine Nummer", "0"))



"One Handed Man" <terry_burnsREMOVE%FOR%NO%(E-Mail Removed)> schrieb im
Newsbeitrag news:etjkfn$(E-Mail Removed)...
> I set the binding up at design time. It builds without error, but refuses

to
> allow the insert because the control is bound to a data source.
>
>
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
>
> Dim NR As DataRow = Ds1.Tables("People").NewRow
>
> Dim t As DataTable = Ds1.Tables("People")
>
> NR("FirstName") = "All Items"
>
> Ds1.Tables("People").Rows.InsertAt(NR, 0) <<<<<< ERROR Cannot insert when
> data source is selected
>
> End Sub
>
>
> --
> Regards - One Handed Man
>
> Author : Fish .NET & Keep .NET
>
> ==============================
> "Thomas Robertson" <(E-Mail Removed)> wrote in message
> news:%23puAlh$(E-Mail Removed)...
> > What exception do you get? I am using the below code and it works
> > fine...
> >
> > ' load the ProductList listbox
> > If Not (lbProductList Is Nothing) Then
> > lbProductList.DataSource = oStoreData.Products.GetProductQNav()
> > lbProductList.DataTextField = "name"
> > lbProductList.DataValueField = "code"
> > lbProductList.DataBind()
> > lbProductList.Items.Insert(0, "Product List")
> > lbProductList.Items(0).Value = "-"
> > lbProductList.Items.Insert(0, "-Select Product To View-")
> > lbProductList.Items(0).Value = ""
> > End If
> >
> > Maybe it is when you are binding it? I bind then do whatever else I

> have
> > to do afterwards. Have you stepped through it and found when it is

bombing
> > out on you? If that didn't help figure out where it is failing and post

> the
> > code. I am sure someone can figure it out.
> >
> > HTH,
> >
> > Tom
> >
> > "One Handed Man" <terry_burnsREMOVE%FOR%NO%(E-Mail Removed)> wrote

in
> > message news:eaDYZQ%(E-Mail Removed)...
> > > Scenario
> > > ---------
> > > Usng a data bound listbox to a table containing sorted data. ListBox

has
> > > sorted turned off so takes sorted data straight from the table.
> > > Problem
> > > ---------
> > > Want to be able to insert an item at start of list before sorted items

> > from
> > > table.
> > >
> > > 1.) cannot use listbox insert method when lb is databound because it

> > throws
> > > a runtime exception
> > > 2.) tried to insertAt( Object, 0 ) // at first position, but it

allways
> > goes
> > > to the end.
> > >
> > > So . . .
> > >
> > > Why is 2.) Happening and any ideas for coding around this problem ?
> > >
> > > Any help is appreciated
> > >
> > >
> > >
> > >
> > > --
> > > Regards - One Handed Man
> > >
> > > Author : Fish .NET & Keep .NET
> > >
> > > ==============================
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Index entry shows up in bold in the index Aris Meneshian Microsoft Word Document Management 10 12th Jun 2009 01:30 PM
Inserting an index entry into index $0 of file 25 Daddy Windows XP General 3 6th Feb 2008 01:04 PM
On Insert or Update - index out of bound error Gina Microsoft Access VBA Modules 4 19th Apr 2005 10:01 PM
RE: Insert unbound item in bound listbox =?Utf-8?B?RG90TmV0TWFuaWFj?= Microsoft Dot NET Framework Forms 0 23rd Sep 2004 06:15 PM
Insert unbound item in bound listbox =?Utf-8?B?V2FkZQ==?= Microsoft Dot NET Framework Forms 0 22nd Sep 2004 06:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:13 PM.