mikesims10670
asked on
Loop through and delete an item from a combo box
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.
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.
ASKER
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Wayne, this is perfect! Thank you.
I'm have one more problem, and I created a question for it here:
https://www.experts-exchange.com/index.jsp?qid=22969536
Please take a look at it if you would.
Thank you,
Mike Sims
I'm have one more problem, and I created a question for it here:
https://www.experts-exchange.com/index.jsp?qid=22969536
Please take a look at it if you would.
Thank you,
Mike Sims
ASKER
Nevermind the last question, I figured it out.
ASKER
Thank you very much. This saved me a lot of time.
mike@simtechdata.com
mike@simtechdata.com
Try iterating through the bound datatable....
For Each dr As DataRow In CType(cboCollector.DataSou
If dr("ColGUID") = "whatever" Then
dr.Delete()
End If
Next
Regards,
Wayne