?
Solved

Loop through and delete an item from a combo box

Posted on 2007-11-18
6
Medium Priority
?
1,375 Views
Last Modified: 2013-11-17
I set up a combo box in VB.NET CF using the following code:

sql = "Select ColGUID, Collector From Collectors"  (this is WAY over simplified, but the number of columns and the type of data is the same)

Dim ds As New DataSet
Dim da As New SqlCeDataAdapter(sql, MainForm.conn)
da.Fill(ds, "Collectors")

If ds.Tables(0).Rows.Count < 1 Then
     MsgBox("All of the dust collectors in this location have been recorded today", MsgBoxStyle.OkCancel)
     da.Dispose()
     ds.Dispose()
     MainForm.G.ExitApp(True)
End If

With cboCollector
     .DataSource = ds.Tables("Collectors")
     .DisplayMember = "Collector"
     .ValueMember = "ColGUID"
End With
da.Dispose()
ds.Dispose()
cboCollector.Enabled = True

Now I would like to go back and iterate through each "line" in the combobox and delete items based on a specific criteria ... for example, I would like to do something like this:

With each item in cboCollector
   If condition true then DeleteItem
End With

I've looked at different examples and none of them seem to work ... is this even possible with compact framework? I've tried to exclude the itmes by being creative with my sql statement, but the sql command is just too darn complicated and I can't make it work. The item(s) I want to delete are really simple to find after the combobox is populated.
0
Comment
Question by:mikesims10670
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 20310546
Hi mikesims10670,

Try iterating through the bound datatable....

        For Each dr As DataRow In CType(cboCollector.DataSource, DataTable).Rows
            If dr("ColGUID") = "whatever" Then
                dr.Delete()
            End If
        Next

Regards,

Wayne
0
 
LVL 1

Author Comment

by:mikesims10670
ID: 20310602
That seems to be working, but it fires the SelectedIndexChanged of cboCollector and actually chooses the first value in the list which then prompts the user as though they had chosed that item in the list. Do you have any idea how I can prevent this?
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 2000 total points
ID: 20310654
The normal method is to have a class level boolean variable (ie, declared outside all procedures), and set it to true when deleting the item/s....

    Private Deleting As Boolean

...then set it to true when deleting, and set it back to false when done....

        Deleting = True
        For Each dr As DataRow In CType(cboCollector.DataSource, DataTable).Rows
            If dr("ColGUID") = "whatever" Then
                dr.Delete()
            End If
        Next
        Deleting = False

...and then in the SelectedIndexChanged event, use this line to exit the sub....

        If Deleting Then Exit Sub

Wayne
0
Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

 
LVL 1

Author Comment

by:mikesims10670
ID: 20310728
Wayne, this is perfect! Thank you.

I'm have one more problem, and I created a question for it here:
http://www.experts-exchange.com/index.jsp?qid=22969536

Please take a look at it if you would.

Thank you,

Mike Sims
0
 
LVL 1

Author Comment

by:mikesims10670
ID: 20310746
Nevermind the last question, I figured it out.
0
 
LVL 1

Author Closing Comment

by:mikesims10670
ID: 31409880
Thank you very much. This saved me a lot of time.
mike@simtechdata.com
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

770 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