Hello everybody!
I'm interested in select all items in checkedlistbox, have anyone code?:)
Printable View
Hello everybody!
I'm interested in select all items in checkedlistbox, have anyone code?:)
To uncheck them change the 'True' to 'False'.Code:For i As Integer = 0 To CheckedListBox1.Items.Count - 1
CheckedListBox1.SetItemChecked(i, True)
Next i
Just loop through the items and check each one. Use a For loop and call SetItemChecked for each index.
thanks:)
Quote:
Originally Posted by jmcilhinney
Hi.
I i need some help.
I am doing something like this..I got a checkedlistbox inside contain a few numbers. when i checked and select a few numbers den i press send right..the program will send a msg to the numbers selected.
Cos currently example when i select only 2 numbers right? my program will send to every numbers in the checkedlistbox which is not wad i want..
Hope you all can help me..
Thanks in advance.
Hey,
In this instance, you are going to want to loop through te CheckedItems Collection, i.e.
GaryCode:For i As Integer = 0 To CheckedListBox1.CheckedItems.Count
Next i
Hmmm. I see sth like this before.. this is to loop through the checkedlistbox right?Quote:
Originally Posted by gep13
but how do i send msg to the selected numbers?
i need to use sth like if else izzt? for example if blah blah is selected den send msg else do nothing? izzt sth like this?
Hey,
I think you missed what I suggested.
The code that I gave you will only loop through the checkboxes that are checked, it will not loop through all of them.
Is this not what you want?
Gary
Although, one slight correction on the above:
GaryCode:For i As Integer = 0 To CheckedListBox1.CheckedItems.Count - 1
Next i
I see..
So it will loop through the checkedlistbox and check for selected right?
but if i wanna do sth for example send msg to the selected right? wad is the code i need to type?
Yes, the above code will loop through all the checked items in the checkedlistbox and you can do something for each one.
You are going to have to be a bit more clear about what you mean about send msg though?!? Are you talking about sending an email?
Gary
okie thanks.
i am not sending email..i am using a sim card which is place inside a GSM modem to send msg to other phones by selecting the phone numbers in the checkedlistbox..
the problem i have now is no matter wad number i select..the program will send to every numbers in the checkedlistbox..:(
Well assuming that the mobile number is the text of the checklistbox item, you can get that information using:
And from there you could use the number to do the sending of the message.Code:For i As Integer = 0 To CheckedListBox1.CheckedItems.Count - 1
MessageBox.Show(CheckedListBox1.CheckedItems.Item(i).ToString())
Next i
Gary
hmmm..so i assume
For i As Integer = 0 To CheckedListBox1.CheckedItems.Count - 1 (will loop through the checkedlistbox right?
but as for
MessageBox.Show(CheckedListBox1.CheckedItems.Item(i).ToString())
and Next i right...wad they do?
Sorry but i am very weak in vb..
Hey,
For and Next go together to complete the looping of the checkedlistbox, so can't have one without the other.
All this is doing is showing the value of the current checkbox. Which is what I thought you wanted.Code:MessageBox.Show(CheckedListBox1.CheckedItems.Item(i).ToString())
To be honest though, if you are struggling with this, I would think you are going to struggle with sending text messages. I think you should maybe read some of the VB.Net Tutorials linked to at the top of this forum.
Gary
Hmmm.. i got no problem with sending text msg cos my friend already help me..
wad i need to do now is onli to loop and check for selected numbers den have a code to send to the numbers.( i have the codes for sending out the msg though)
so wad i need now is to implement a if else statement for example i check that checkedlistbox for selected numbers if detected numbers that are check then it will send the msg to the numbers..
else do nothing right?( i noe else do nothing is wrong..wad is the correct code not to do anything?)
As I have said before, you don't need to check for the check box being checked or not. The code I gave you is looping through ONLY the checked items, hence why I am using the CheckedItems collection. i.e. every item in the for loop is one that you want to do something with.
Have you tried the code that I gave you?
If you drop it into a form you should be able to see it working.
Gary
i see.
but do i have to state wad i need to do with the checked item? (for example send msg to them)
Hey,
I am not sure if we understand eahc other. assuming that the phone nu:ber you want is the checkbox value, what is passed into the MessageBox.Show function above should be able to be passed into your other method for sending the message.
Can you post the code that you are trying to use, maybe it will help to see what you are currently looking at.
Gary
Hmmm..post the whole program code?
not expecting the whole program, no, maybe just the population of the checkboklist, and then the main sms message function.
Hi. i dunno whether you are still here but this is the code that i use..
Private Sub btnShutdownCom3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShutdownCom3.Click
sendMsgTo(CheckedListBox1, strShutdownMsg)
End Sub
and
Private Sub sendMsgTo(ByVal txtbox As CheckedListBox, ByVal msg As String)
Dim strSendStatus As String = ""
Dim index As Integer
initialisePorts()
For index = 0 To CheckedListBox1.CheckedItems.Count - 1
MessageBox.Show(CheckedListBox1.CheckedItems.Item(index).ToString())
Next index
'initialisePorts()
SerialPort1.WriteLine("AT+CMGS=" + txtbox.Items.Item(index) + vbCr) 'AT send sms command/selected txtbox
txtMainPanel.Text += vbNewLine & ".....SMS Sending in Progress....." 'displays on the mainpanel (a textbox)
txtMainPanel.Refresh()
System.Threading.Thread.Sleep(750) 'delay
SerialPort1.WriteLine(msg) 'sends shutdown/restartmsg
System.Threading.Thread.Sleep(500) 'delay
SerialPort1.WriteLine(Chr(26))
System.Threading.Thread.Sleep(5500) 'delay
strSendStatus = SerialPort1.ReadExisting()
txtMainPanel.Text += vbNewLine + strSendStatus
If InStr(strSendStatus, "OK") <> 0 Then
txtMainPanel.Text += vbNewLine + "SMS message successfully sent!"
txtMsg.Clear()
MessageBox.Show("SMS message successfully sent")
Else
MessageBox.Show("Try again")
End If
SerialPort1.Close()
End Sub
Can I take it from the rep that you gave that you have it working?
I can't see in the above where you pass the phone number to the serial port, but what you would need to do in the above woud be something like this:
Here I have wrapped the code to send the message within the for loop so that it will send a message for each checked item. Whether you need to put the number in the above, put:Code:Private Sub sendMsgTo(ByVal txtbox As CheckedListBox, ByVal msg As String)
Dim strSendStatus As String = ""
Dim index As Integer
'initialisePorts()
initialisePorts()
For index = 0 To CheckedListBox1.CheckedItems.Count - 1
SerialPort1.WriteLine("AT+CMGS=" + txtbox.Items.Item(index) + vbCr) 'AT send sms command/selected txtbox
txtMainPanel.Text += vbNewLine & ".....SMS Sending in Progress....." 'displays on the mainpanel (a textbox)
txtMainPanel.Refresh()
System.Threading.Thread.Sleep(750) 'delay
SerialPort1.WriteLine(msg) 'sends shutdown/restartmsg
System.Threading.Thread.Sleep(500) 'delay
SerialPort1.WriteLine(Chr(26))
System.Threading.Thread.Sleep(5500) 'delay
strSendStatus = SerialPort1.ReadExisting()
txtMainPanel.Text += vbNewLine + strSendStatus
If InStr(strSendStatus, "OK") <> 0 Then
txtMainPanel.Text += vbNewLine + "SMS message successfully sent!"
txtMsg.Clear()
MessageBox.Show("SMS message successfully sent")
Else
MessageBox.Show("Try again")
End If
Next index
SerialPort1.Close()
End Sub
Having said that though, I am not sure that this is the correct approach. It might be better to isolate the sending of the message, and rather than pass a checkedboxlist, pass just the number and the message, and then do the looping elsewhere.Code:CheckedListBox1.CheckedItems.Item(index).ToString()
Just a thought.
Gary