|
-
Jan 8th, 2009, 12:15 PM
#1
Thread Starter
Addicted Member
[RESOLVED] CheckedListBox select all
Hello everybody!
I'm interested in select all items in checkedlistbox, have anyone code?
Last edited by Hack; Jan 8th, 2009 at 01:09 PM.
Reason: Added RESOLVED to thread title and green resolve checkmark
-
Jan 8th, 2009, 12:22 PM
#2
-
Jan 8th, 2009, 12:22 PM
#3
Re: CheckedListBox select all
Just loop through the items and check each one. Use a For loop and call SetItemChecked for each index.
-
Jan 8th, 2009, 12:51 PM
#4
Thread Starter
Addicted Member
Re: CheckedListBox select all
thanks
-
Feb 11th, 2009, 11:36 AM
#5
New Member
Re: CheckedListBox select all
 Originally Posted by jmcilhinney
Just loop through the items and check each one. Use a For loop and call SetItemChecked for each index.
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.
-
Feb 11th, 2009, 11:53 AM
#6
Re: [RESOLVED] CheckedListBox select all
Hey,
In this instance, you are going to want to loop through te CheckedItems Collection, i.e.
Code:
For i As Integer = 0 To CheckedListBox1.CheckedItems.Count
Next i
Gary
-
Feb 11th, 2009, 11:59 AM
#7
New Member
Re: [RESOLVED] CheckedListBox select all
 Originally Posted by gep13
Hey,
In this instance, you are going to want to loop through te CheckedItems Collection, i.e.
Code:
For i As Integer = 0 To CheckedListBox1.CheckedItems.Count
Next i
Gary
Hmmm. I see sth like this before.. this is to loop through the checkedlistbox right?
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?
-
Feb 11th, 2009, 12:03 PM
#8
Re: [RESOLVED] CheckedListBox select all
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
-
Feb 11th, 2009, 12:05 PM
#9
Re: [RESOLVED] CheckedListBox select all
Although, one slight correction on the above:
Code:
For i As Integer = 0 To CheckedListBox1.CheckedItems.Count - 1
Next i
Gary
-
Feb 11th, 2009, 12:08 PM
#10
New Member
Re: [RESOLVED] CheckedListBox select all
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?
-
Feb 11th, 2009, 12:10 PM
#11
Re: [RESOLVED] CheckedListBox select all
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
-
Feb 11th, 2009, 12:19 PM
#12
New Member
Re: [RESOLVED] CheckedListBox select all
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..
-
Feb 11th, 2009, 12:22 PM
#13
Re: [RESOLVED] CheckedListBox select all
Well assuming that the mobile number is the text of the checklistbox item, you can get that information using:
Code:
For i As Integer = 0 To CheckedListBox1.CheckedItems.Count - 1
MessageBox.Show(CheckedListBox1.CheckedItems.Item(i).ToString())
Next i
And from there you could use the number to do the sending of the message.
Gary
-
Feb 11th, 2009, 12:34 PM
#14
New Member
Re: [RESOLVED] CheckedListBox select all
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..
-
Feb 11th, 2009, 12:40 PM
#15
Re: [RESOLVED] CheckedListBox select all
Hey,
For and Next go together to complete the looping of the checkedlistbox, so can't have one without the other.
Code:
MessageBox.Show(CheckedListBox1.CheckedItems.Item(i).ToString())
All this is doing is showing the value of the current checkbox. Which is what I thought you wanted.
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
-
Feb 11th, 2009, 12:55 PM
#16
New Member
Re: [RESOLVED] CheckedListBox select all
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?)
-
Feb 11th, 2009, 12:58 PM
#17
Re: [RESOLVED] CheckedListBox select all
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
-
Feb 11th, 2009, 01:10 PM
#18
New Member
Re: [RESOLVED] CheckedListBox select all
i see.
but do i have to state wad i need to do with the checked item? (for example send msg to them)
-
Feb 11th, 2009, 02:14 PM
#19
Re: [RESOLVED] CheckedListBox select all
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
-
Feb 11th, 2009, 02:38 PM
#20
New Member
Re: [RESOLVED] CheckedListBox select all
Hmmm..post the whole program code?
-
Feb 11th, 2009, 04:37 PM
#21
Re: [RESOLVED] CheckedListBox select all
not expecting the whole program, no, maybe just the population of the checkboklist, and then the main sms message function.
-
Feb 11th, 2009, 10:57 PM
#22
New Member
Re: [RESOLVED] CheckedListBox select all
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
-
Feb 12th, 2009, 02:33 AM
#23
Re: [RESOLVED] CheckedListBox select all
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:
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
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:
CheckedListBox1.CheckedItems.Item(index).ToString()
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.
Just a thought.
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|