Results 1 to 12 of 12

Thread: and into a blank listbox...?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    128

    and into a blank listbox...?

    Hi there...

    I need to produce a facility to add items into a blank listbox from a full list box, and then produce reports based on the ones i have added into the blank one.

    it will be a web application using aspx and aspx.vb files

    i have creatde a blank web form and have added two list boxes and a button to it, where do i goes from here...?

    please help, or show me a link to the code i need,
    thanks

    tom

  2. #2
    Member HumanCompiler's Avatar
    Join Date
    Dec 2002
    Location
    Decatur, IN USA
    Posts
    52
    Just make sure you have .EnableViewState set to true for both of your listboxes, then all you have to do is something like this in a button for transferring one item to the other listbox

    VB Code:
    1. ListBoxNew.Items.Add(ListBoxMain.Items(ListBoxMain.SelectedIndex))

    Enabling the ViewState, will make it so the new listbox retains its list on each postback
    -Erik Porter
    .NET MVP

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    128
    have tried that... am getting this error?

    Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index


    my code:

    PHP Code:
    Public Class TestLists
        Inherits System
    .Web.UI.Page
        
    Protected WithEvents ListBoxMain As System.Web.UI.WebControls.ListBox
        
    Protected WithEvents Button As System.Web.UI.WebControls.Button
        
    Protected WithEvents ListBoxNew As System.Web.UI.WebControls.ListBox
        
    Protected WithEvents TagList As ReportClient.TagList
        Dim Comp 
    As Component1 = New Component1()

    #Region " Web Form Designer Generated Code "

        
    'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.TagList = New ReportClient.TagList()
            CType(Me.TagList, System.ComponentModel.ISupportInitialize).BeginInit()
            '
            'TagList
            '
            
    Me.TagList.DataSetName "TagList"
            
    Me.TagList.Locale = New System.Globalization.CultureInfo("en-GB")
            
    Me.TagList.Namespace = "http://www.tempuri.org/TagList.xsd"
            
    CType(Me.TagListSystem.ComponentModel.ISupportInitialize).EndInit()

        
    End Sub

        
    Private Sub Page_Init(ByVal sender As System.ObjectByVal e As System.EventArgsHandles MyBase.Init
            
    'CODEGEN: This method call is required by the Web Form Designer
            '
    Do not modify it using the code editor.
            
    InitializeComponent()
        
    End Sub

    #End Region

        
    Private Sub Page_Load(ByVal sender As System.ObjectByVal e As System.EventArgsHandles MyBase.Load
            ListBoxMain
    .EnableViewState True
            ListBoxNew
    .EnableViewState True
            Comp
    .TagList.Fill(TagList)
            
    ListBoxMain.DataBind()
        
    End Sub

        
    Private Sub Button_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles Button.Click
            ListBoxNew
    .Items.Add(ListBoxMain.Items(ListBoxMain.SelectedIndex))
        
    End Sub
    End 
    Class 

  4. #4
    Member HumanCompiler's Avatar
    Join Date
    Dec 2002
    Location
    Decatur, IN USA
    Posts
    52
    make sure your Page_Load code is inside a "If Not IsPostBack Then" statement to make sure it only executes the first time
    -Erik Porter
    .NET MVP

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    128
    ok, that works now, how do i insert an item into listboxnew when the user double clicks an item in listboxmain??


    i also want to produce a report that shows all item from that listbox, do i have to write the data into a dataset and get the data that way?
    Last edited by tmashley; Dec 16th, 2002 at 10:47 AM.

  6. #6
    Member HumanCompiler's Avatar
    Join Date
    Dec 2002
    Location
    Decatur, IN USA
    Posts
    52
    double clicking is something that happens client side and has nothing to do with asp.net...you'd have to write up some javascript to do that.
    -Erik Porter
    .NET MVP

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    128
    any examples you know of?also what about the reporting?
    Last edited by tmashley; Dec 17th, 2002 at 05:55 AM.

  8. #8
    Member HumanCompiler's Avatar
    Join Date
    Dec 2002
    Location
    Decatur, IN USA
    Posts
    52
    I do my best to stay away from client-scripting

    As for the "reporting", just loop through the items collection in the new listbox and you'll have access to all the items to do with whatever you want
    -Erik Porter
    .NET MVP

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    128
    ok, that sounds good, i am new to this, how shall i go about this example code please...

    thanks

  10. #10
    Member HumanCompiler's Avatar
    Join Date
    Dec 2002
    Location
    Decatur, IN USA
    Posts
    52
    you can use a for or a for each statement

    VB Code:
    1. Dim i As Int16
    2. For i = 0 To ListBoxNew.Items.Count - 1
    3.      Response.Write("Item " & i & ListBoxNew.Items(i).Text & "<br>")
    4. Next

    something like that should work
    -Erik Porter
    .NET MVP

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    128
    i will need to retreive data from another sql table getting all the data related to each item of the list, will i have to perform "select" statements for each item, if so how?

    i want to get all the values that are in the listbox and perform this action on each...

    PHP Code:
    rpTestReport.RecordSelectionFormula "{tblTable.itmItem} = " "'" ListBoxItemN "'" 
    is this possible??
    Last edited by tmashley; Dec 18th, 2002 at 04:36 AM.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    128
    bump

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width