Help with retreiving data from listbox!!

Results 1 to 3 of 3

Thread: Help with retreiving data from listbox!!

  1. #1
    Join Date
    Dec 1969

    Default Help with retreiving data from listbox!!

    Hello, <BR><BR>I&#039;m using ADO.NET to connect to a database, than trying to run a report depending values selected from two listboxes. When the values are hardcoded, it works, but when using the valuemember of the listboxes, the field name appears on my selection formula. Can you please help. <BR><BR>Valuemember of Listbox1, listbox2 are fields COUNTRY and SN, the problem is the data are not retreived, therefore the select formula looks like this: <BR><BR>{} in [COUNTRY] and left({,3) in [SN] <BR><BR>as oppposed to like this: <BR><BR>{} in [&#039;BE&#039;, &#039;CA&#039;] and left({,3) in [&#039;104&#039;, &#039;105&#039;] <BR><BR>Help...Thanks. <BR><BR>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click <BR> &#039;Dim textvalue As String <BR> &#039;Dim chaptervalue As String <BR> &#039;textvalue = "&#039;BE&#039;, &#039;CA&#039;, &#039;FR&#039;, &#039;GE&#039;" <BR> &#039;chaptervalue = "10411" <BR> Dim myaop6report As New aop6report() <BR> Dim myaop6viewer As New AOP6VIEWER() <BR> myaop6report.RecordSelectionFormula = "{} in [" & ListBox2.ValueMember & "] and left({},3) in [" & "&#039;" & ListBox1.ValueMember & "&#039;" & "]" <BR><BR> MsgBox(myaop6report.RecordSelectionFormula) <BR> With myaop6viewer <BR> .CrystalViewer.ReportSource = myaop6report <BR> .Show() <BR> End With <BR> End Sub <BR><BR><BR>Thanks. <BR>

  2. #2
    Join Date
    Dec 1969
    Indianapolis, IN

    Default RE: Help with retreiving data from listbox!!

    For a listbox, you can&#039;t just look at the listbox.valuemember. That won&#039;t help. You need to find all of the selected items. So what you need to do is have a For Each ... Next loop setup for Listbox 1 and ListBox 2 and look to see if that item is selected or not. If it is, you&#039;ll need to concatenate that item&#039;s value into a string (maybe call it strRecordSelFormula) which will be used towards the myaop6report.RecordSelectionFormula after you&#039;ve completed both loops.

  3. #3
    Join Date
    Dec 1969

    Default Yes, using ValueMember wrong...

    ...that doesn&#039;t get the *VALUE* of the field. It just gets the *NAME* of which of the values will be returned.<BR><BR>You need something on the order of this kind of code:<BR><BR> Dim si As ListBox.SelectedObjectCollection = Me.ListBox1.SelectedItems()<BR> Dim i As Integer<BR> For i = 0 To si.Count - 1<BR> MsgBox(CStr(si.Item(i)))<BR> Next<BR><BR>[Well, that&#039;s kind of dumb...but you get the idea.]<BR><BR>

Posting Permissions

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