Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have made two windows in WPF. first is Mainwindow.xmal in which there is a combobox.


i want to access combo-box items from login to mainwindow window

please suggest code for this.


------------------------------------
Screen:
------------------------------------
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Net.Mail;
using System.Net.NetworkInformation;

<pre lan="c#">
namespace Mail_Bird
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        SmtpClient smtp = new SmtpClient();
        MailMessage mail = new MailMessage();
        Login login = new Login();

        public MainWindow()
        {
            InitializeComponent();
            smtp.UseDefaultCredentials = false;
            smtp.EnableSsl = true;
            
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            mail.Subject = Text_Subject.Text.Trim();
            mail.To.Add(Text_To.Text.Trim());
            mail.From = new MailAddress(Text_From.Text);
            mail.Body = Text_Body.Text;
            mail.IsBodyHtml = true;
            
            smtp.Credentials=new System.Net.NetworkCredential(login.Text_user.Text+"@"+login.Combo1.SelectedItem,login.Text_pass.ToString());

            if (login.Combo1.SelectedItem=="gmail.com")  /* Here it shows green underlining stating that (possible unintended refrence comparison; to get the value comparison,cast the left hand side to string) */
            
{
             
                smtp.Host = "smtp.gmail.com";
                smtp.Port=587;
            }
            try
            {
                
                smtp.Send(mail);
                MessageBox.Show("Mail Sent Successfully !");
               
            }
            catch(Exception ex)
            {
                ex.ToString();
            }

---------------------------------------------------
on if condition...
/* Here it shows green underlining stating that (possible unintended refrence comparison; to get the value comparison,cast the left hand side to string) */
Posted
Updated 22-Apr-13 18:22pm
v4
Comments
Naz_Firdouse 22-Apr-13 5:13am    
you mean you want to pass combo box values to another window because you mentioned that Combobox is in MainWnidow...

1 solution

you can use a global collection that holding the itemsource of combobox. first declare a public collection of combobox .
C#
private observablecollection<string>comboboxObservableCollection;</string>


in selected item event of combobox , write the code like below.

C#
comboboxObservableCollection=this.combobox.selecteditem;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900