Ask a Question related to Microsoft Access, Design and Development.

  1. #1

    Default ListBox Question

    Dear All,

    Can you programatically select an item in a ListBox based
    on the value entered in a text box from the after_update
    event? I have tried the following code which does not work:

    forms!Form1!MyListBox.SelectedItem = me!Text1.text, or
    forms!Form1!MyListBox.value.column(1) = me!Text1.text

    The bound column of the ListBox is Column(0). I want the
    TextBox to be used to select the Column(1) value.

    Thanks for all help...

    Alastair MacFarlane





    Alastair MacFarlane Guest

  2. Similar Questions and Discussions

    1. listbox to populate a listbox
      I am trying to use a listbox that I have setup using flash remoting call to a db. What I want to happen is when you click on a item in first the...
    2. click listbox and refresh another listbox
      Can someone guide me to a resource on building set of drill-down listboxes? Basically I want to have 4 listboxes. The first starts out with...
    3. Item label displays as "," when moving from listbox to listbox
      I have 2 listboxes: "lb_unselected" and "lb_selected". The first thing in the actions is loop through an array populating these two listboxes. ...
    4. now desparate! - 1st listbox contents disappears when 2nd listbox appears?
      On 23 Jun 2003 12:57:45 -0700, KathyBurke40@attbi.com (KathyB) wrote: Its been a while since you posted but I will answer anyway. The problem...
    5. Easy listbox question
      Hi, I have a listbox with 3 columns, and I have an event for doubleclick on the listbox, but I do not know the syntax for putting the...
  3. #2

    Default Re: ListBox Question

    Hi,


    The assignment operator assign what is to the right to what is to the left. The syntax should have
    been


    Me.Text1.Value= Forms!Form1!MyComboBox.value.column(1)


    Also note that in Access, the value is held into the property VALUE, not the property TEXT. A
    Value is of data type VARIANT, so it can handle the values NULL without problem. A Text data type
    is a STRING and cannot handle a Variant, so, it cannot handle a NULL, which is a frequent value in
    databases (outer join, or otherwise). Also, in Access, the Text property is only valid when the
    control has the focus, it then hold the data like it is actually typed by the end user, while Value
    is the last validated (by the control) value (not necessary saved in the table), and OldValue the
    last committed value (in the record, validatated in the table).


    If the list box has the possibility to let the user select more than one value (multiselect), you
    have to use the ItemData property of the Listbox, after you " point" to the selected row of your
    liking (see [url]http://www.mvps.org/access/forms/frm0007.htm[/url], or the help file for more examples on how
    to access these data).


    Hoping it may help,
    Vanderghast, Access MVP


    "Alastair MacFarlane" <amacfarlane@blueyonder.co.uk> wrote in message
    news:0d0e01c3453e$db6823f0$a301280a@phx.gbl...
    > Dear All,
    >
    > Can you programatically select an item in a ListBox based
    > on the value entered in a text box from the after_update
    > event? I have tried the following code which does not work:
    >
    > forms!Form1!MyListBox.SelectedItem = me!Text1.text, or
    > forms!Form1!MyListBox.value.column(1) = me!Text1.text
    >
    > The bound column of the ListBox is Column(0). I want the
    > TextBox to be used to select the Column(1) value.
    >
    > Thanks for all help...
    >
    > Alastair MacFarlane
    >
    >
    >
    >
    >

    Michel Walsh Guest

  4. #3

    Default Re: ListBox Question

    Vanderghast,

    Thanks for the reply! I am sorry if I am confusing the
    issue. What I would like is to enter text in a text box
    and the value in the Value property of the TextBox would
    highlight itself in column(1) of a ListBox? and not the
    other way round. To obtain the value from a selected
    ListBox to the TextBox would be straightforward. The
    converse does not work.

    Forms!Form1!MyComboBox.value.column(1)=Me.Text1.Va lue

    Any suggestions?

    Thanks again...

    Alastair MacFarlane



    >-----Original Message-----
    >Hi,
    >
    >
    >The assignment operator assign what is to the right to
    what is to the left. The syntax should have
    >been
    >
    >
    > Me.Text1.Value= Forms!Form1!MyComboBox.value.column(1)
    >
    >
    >Also note that in Access, the value is held into the
    property VALUE, not the property TEXT. A
    >Value is of data type VARIANT, so it can handle the
    values NULL without problem. A Text data type
    >is a STRING and cannot handle a Variant, so, it cannot
    handle a NULL, which is a frequent value in
    >databases (outer join, or otherwise). Also, in Access,
    the Text property is only valid when the
    >control has the focus, it then hold the data like it is
    actually typed by the end user, while Value
    >is the last validated (by the control) value (not
    necessary saved in the table), and OldValue the
    >last committed value (in the record, validatated in the
    table).
    >
    >
    >If the list box has the possibility to let the user
    select more than one value (multiselect), you
    >have to use the ItemData property of the Listbox, after
    you " point" to the selected row of your
    >liking (see [url]http://www.mvps.org/access/forms/frm0007.htm[/url],
    or the help file for more examples on how
    >to access these data).
    >
    >
    >Hoping it may help,
    >Vanderghast, Access MVP
    >
    >
    >"Alastair MacFarlane" <amacfarlane@blueyonder.co.uk>
    wrote in message
    >news:0d0e01c3453e$db6823f0$a301280a@phx.gbl...
    >> Dear All,
    >>
    >> Can you programatically select an item in a ListBox
    based
    >> on the value entered in a text box from the after_update
    >> event? I have tried the following code which does not
    work:
    >>
    >> forms!Form1!MyListBox.SelectedItem = me!Text1.text, or
    >> forms!Form1!MyListBox.value.column(1) = me!Text1.text
    >>
    >> The bound column of the ListBox is Column(0). I want the
    >> TextBox to be used to select the Column(1) value.
    >>
    >> Thanks for all help...
    >>
    >> Alastair MacFarlane
    >>
    >>
    >>
    >>
    >>
    >
    >
    >.
    >
    Alastair MacFarlane Guest

  5. #4

    Default Re: ListBox Question

    Vanderghast,

    Thanks for the reply! I am sorry if I am confusing the
    issue. What I would like is to enter text in a text box
    and the value in the Value property of the TextBox would
    highlight itself in column(1) of a ListBox? and not the
    other way round. To obtain the value from a selected
    ListBox to the TextBox would be straightforward. The
    converse does not work.

    Forms!Form1!MyComboBox.value.column(1)=Me.Text1.Va lue

    Any suggestions?

    Thanks again...

    Alastair MacFarlane



    >-----Original Message-----
    >Hi,
    >
    >
    >The assignment operator assign what is to the right to
    what is to the left. The syntax should have
    >been
    >
    >
    > Me.Text1.Value= Forms!Form1!MyComboBox.value.column(1)
    >
    >
    >Also note that in Access, the value is held into the
    property VALUE, not the property TEXT. A
    >Value is of data type VARIANT, so it can handle the
    values NULL without problem. A Text data type
    >is a STRING and cannot handle a Variant, so, it cannot
    handle a NULL, which is a frequent value in
    >databases (outer join, or otherwise). Also, in Access,
    the Text property is only valid when the
    >control has the focus, it then hold the data like it is
    actually typed by the end user, while Value
    >is the last validated (by the control) value (not
    necessary saved in the table), and OldValue the
    >last committed value (in the record, validatated in the
    table).
    >
    >
    >If the list box has the possibility to let the user
    select more than one value (multiselect), you
    >have to use the ItemData property of the Listbox, after
    you " point" to the selected row of your
    >liking (see [url]http://www.mvps.org/access/forms/frm0007.htm[/url],
    or the help file for more examples on how
    >to access these data).
    >
    >
    >Hoping it may help,
    >Vanderghast, Access MVP
    >
    >
    >"Alastair MacFarlane" <amacfarlane@blueyonder.co.uk>
    wrote in message
    >news:0d0e01c3453e$db6823f0$a301280a@phx.gbl...
    >> Dear All,
    >>
    >> Can you programatically select an item in a ListBox
    based
    >> on the value entered in a text box from the after_update
    >> event? I have tried the following code which does not
    work:
    >>
    >> forms!Form1!MyListBox.SelectedItem = me!Text1.text, or
    >> forms!Form1!MyListBox.value.column(1) = me!Text1.text
    >>
    >> The bound column of the ListBox is Column(0). I want the
    >> TextBox to be used to select the Column(1) value.
    >>
    >> Thanks for all help...
    >>
    >> Alastair MacFarlane
    >>
    >>
    >>
    >>
    >>
    >
    >
    >.
    >
    Alastair MacFarlane Guest

  6. #5

    Default Re: ListBox Question

    Hi,
    Not sure if this is the best way, but it will work:

    Dim i As Integer
    For i = 0 To Me.List0.ListCount - 1
    If Me.List0.Column(1, i) = Me.Text3 Then
    Me.List0.Selected(i) = True
    End If
    Next

    --
    HTH
    Dan Artuso, Access MVP


    "Alastair MacFarlane" <amacfarlane@blueyonder.co.uk> wrote in message
    news:0d0e01c3453e$db6823f0$a301280a@phx.gbl...
    > Dear All,
    >
    > Can you programatically select an item in a ListBox based
    > on the value entered in a text box from the after_update
    > event? I have tried the following code which does not work:
    >
    > forms!Form1!MyListBox.SelectedItem = me!Text1.text, or
    > forms!Form1!MyListBox.value.column(1) = me!Text1.text
    >
    > The bound column of the ListBox is Column(0). I want the
    > TextBox to be used to select the Column(1) value.
    >
    > Thanks for all help...
    >
    > Alastair MacFarlane
    >
    >
    >
    >
    >

    Dan Artuso Guest

  7. #6

    Default listbox question

    I have the following code in my Page_Load event to populate a listbox
    from a database :

    if (!(Page.IsPostBack))
    {
    SqlConnection objConnection = new
    SqlConnection(ConfigurationSettings.AppSettings["strConnectTransitTest"]
    );
    string strTelcoNumber = "SELECT DISTINCT OSValue FROM CallTypeSwitch
    ORDER BY OSValue";

    //You must open the connection before populating the DataReader
    objConnection.Open();

    SqlCommand objCmd = new SqlCommand(strTelcoNumber, objConnection);

    //Create/Populate the DataReader
    SqlDataReader objDataReader = null;
    objDataReader = objCmd.ExecuteReader();

    //Databind the DataReader to the listbox Web control
    lstRoutes.DataSource = objDataReader;
    lstRoutes.DataBind();
    }

    What I want to do is to get rid of the IsPostback so that if the
    database is updated the listbox will also be updated. But in order to
    do this I need to store the value chosen by the user and set the listbox
    to that value on my Submit button click event. I think ViewState might
    be the right way to go about this but I have no real experience of using
    this in C#. Does any body know how to do this?


    Any advice would be much appreciated.

    Cheers,

    Mike




    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Mike P Guest

  8. #7

    Default Re: listbox question

    Mike, you'll be happt to hear that it's pretty darn easy.

    From the code behind page ViewState functions very similarly to a Session or
    Application variable (as far as setting and retrieving it).

    Now, I program mostly in VB.Net, but the syntax shouldn't be too different.
    Just look at how you set a Session or Application level variable in c# and
    ViewState will be about the same.

    In VB you set it like this:

    ViewState("[Your Key Name Here]") = [Your Object Here]

    Or

    ViewState.Add("[Your Key Name Here]", [Your Object Here])

    Now, I question for your purposes here if you even need to use viewstate.

    If all you're worried about is resetting the list box to the item a user
    chose then wouldn't you get the item chosen, recreate the list box, and then
    reselect the item?

    This would all happen server side in one single trip wouldn't it?

    If there was a post back to the client in the middle then you'd need to
    store the value in view state, but otherwise why not just store it in a
    regular old variable?

    Sincerely,

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    [url]www.aboutfortunate.com[/url]

    "Out of chaos comes order."
    Nietzche
    "Mike P" <mrp@telcoelectronics.co.uk> wrote in message
    news:epobtWBXDHA.3248@tk2msftngp13.phx.gbl...
    > I have the following code in my Page_Load event to populate a listbox
    > from a database :
    >
    > if (!(Page.IsPostBack))
    > {
    > SqlConnection objConnection = new
    > SqlConnection(ConfigurationSettings.AppSettings["strConnectTransitTest"]
    > );
    > string strTelcoNumber = "SELECT DISTINCT OSValue FROM CallTypeSwitch
    > ORDER BY OSValue";
    >
    > //You must open the connection before populating the DataReader
    > objConnection.Open();
    >
    > SqlCommand objCmd = new SqlCommand(strTelcoNumber, objConnection);
    >
    > //Create/Populate the DataReader
    > SqlDataReader objDataReader = null;
    > objDataReader = objCmd.ExecuteReader();
    >
    > //Databind the DataReader to the listbox Web control
    > lstRoutes.DataSource = objDataReader;
    > lstRoutes.DataBind();
    > }
    >
    > What I want to do is to get rid of the IsPostback so that if the
    > database is updated the listbox will also be updated. But in order to
    > do this I need to store the value chosen by the user and set the listbox
    > to that value on my Submit button click event. I think ViewState might
    > be the right way to go about this but I have no real experience of using
    > this in C#. Does any body know how to do this?
    >
    >
    > Any advice would be much appreciated.
    >
    > Cheers,
    >
    > Mike
    >
    >
    >
    >
    > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    S. Justin Gengo Guest

  9. #8

    Default Re: listbox question

    Justin,

    In the Page_Load event can I set the value of the listbox to the value
    entered by the user after I have re-populated it? And if so, what is
    the syntax for doing this? Or do I have totally the wrong idea ?
    (sorry, I am pretty new to ASP.NET and particularly what I am trying to
    do now)

    Mike




    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Mike P Guest

  10. #9

    Default Re: listbox question

    Justin,

    Thanks! I was struggling with it until I realised that I needed to take
    my list populating code out of Page_Load and into it's own separate
    function. Now it seems to work fine.


    Cheers,

    Mike



    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Mike P Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139