?
Solved

ListBox selection

Posted on 2006-05-19
5
Medium Priority
?
207 Views
Last Modified: 2010-04-23
The code below checks if an item in the list box is checked. If it checked, i add a rate to the current rate. If it is not checked, the rate reamains the same. it works perfectly with one item in the listbox. If i have two items i must select both items or all of the item in order to update the "rate".

Based on that description, the problem is related to the if statement up at the top of the code that analyzes if an item is checked or not.

Summaryzing: I need some help understanding why the code work properly for one item and it does not work properly for more than one item. Again when two items are displayed in the box, i must select both of them or the code thinks that it has either one has been checked.

Thanks

Andre

For i = 0 To (chkEndorsement.Items.Count - 1)
            If chkEndorsement.GetItemCheckState(i) = CheckState.Checked Then
                With rs
                    If Not .BOF Then
                        .MoveFirst()
                        Do While Not .EOF
                            endorsement = rs.Fields.Item("description").Value.ToString
                            endvalue = rs.Fields.Item("id").Value.ToString
                            Grid.Columns("Rate").Value = Val(endvalue) + Grid.Columns("Rate").CellValue(Grid.Row).ToString
                            .MoveNext()
                        Loop
                    End If
                End With
            Else
                LoadRate(formcodeval, township, range, cropclass, cropname, stateid, countyid)
            End If

        Next
0
Comment
Question by:virgilar
  • 2
4 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 16720799
first change from ADO to ADO.NET. Since you are using .NET, it makes sense to start using ADO.NET:

change recordset to DataReader and use datareader in your code:

Dim reader as OleDbDataReader
Dim conn as OleDbConnection
conn = New OleDbConnection("your connection string here")
DIm query as String="SELECT * FROM Table"
conn.Open()
Dim cmd As OleDbCommand = New OleDbCommand(query, conn)
reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
For i = 0 To (chkEndorsement.Items.Count - 1)
            If chkEndorsement.GetItemCheckState(i) = CheckState.Checked Then
               While reader.Read
                            endorsement = reader("description").Value.ToString
                            endvalue = reader("id").Value.ToString
                            Grid.Columns("Rate").Value = Val(endvalue) + Grid.Columns("Rate").CellValue(Grid.Row).ToString
                           
                End While
            Else
                LoadRate(formcodeval, township, range, cropclass, cropname, stateid, countyid)
            End If

        Next
0
 

Author Comment

by:virgilar
ID: 16733673
Thanks, but still does not change the fact that the code only works when all options have been selected in the list box. When there is only one option, it all works fine of course but there are more than one option, i have to select all of them for it to work.
0
 

Author Comment

by:virgilar
ID: 16750904
I have come up with the answer:

 For Each x In Me.chkEndorsement.CheckedItems
                checked = True
                endvalue = Val(endvalue) + Me.chkEndorsement.ValueMember
                Me.Grid.Columns("Rate").Value = Val(rate) + Val(endvalue)
            Next

That code above will do what i was looking for.

thanks

This question can be closed please.
0
 

Accepted Solution

by:
GranMod earned 0 total points
ID: 16974629
PAQed with points refunded (500)

GranMod
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question