Hi,
This application is related to sending group sms and at present Im saving it in the database. When I select the item in the combo box I will get the contacts related to it. Im selecting the contacts using checkbox, I should be able to send sms to the contacts that I check. Just go through the below code
<ListBox Height="326" HorizontalAlignment="Left"
Margin="6,101,0,0" Visibility="Visible"
Name="lbContacts" VerticalAlignment="Top" Width="300" ItemsSource="{Binding}" >
<ListBox.ItemTemplate>
<DataTemplate>
<ListBoxItem>
<StackPanel Orientation="Vertical">
<CheckBox Name="chkContactName" Content="{Binding ContactName}" />
<TextBlock Name="tbMobileNo" Text="{Binding MobileNo}"/>
</StackPanel>
</ListBoxItem>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBox Height="132" HorizontalAlignment="Left" Margin="-13,433,0,0" Name="txtMessage" VerticalAlignment="Top" Width="460" />
<Button Content="Send" Height="72" HorizontalAlignment="Left" Margin="287,566,0,0" Name="btnSend" VerticalAlignment="Top" Width="160" Click="btnSend_Click" />
and the below code is to iterate through all the items in the listbox.
//Im getting the exception as invalid cast exception in the below foreach loop
private void btnSend_Click(object sender, RoutedEventArgs e)
{
List<string> lst = new List<string>()
foreach(ListBoxItem li in lbContacts.Items)
{
CheckBox chk = (CheckBox)li.FindName("chkContactName")
if (chk.IsChecked==true)
{
TextBlock tbmob = (TextBlock)li.FindName("tbMobileNo")
lst.Add(tbmob.Text)
}
}
for (int i = 0
{
SM objsms = new SM()
objsms.FKUserId = fkuserid
objsms.FKContactId = ((Contact)lbContacts.SelectedItem).PKContactId
objsms.Message = txtMessage.Text
objsms.SentDate = System.DateTime.Now
try
{
proxy.InsertSMSAsync(objsms)
MessageBox.Show("SMS sent successfully")
}
catch
{
MessageBox.Show("SMS cannot be sent")
}
}
}
can anyone help me to solve this problem