私はメール受信者のアドレスを含むコンボボックスを持っています。ドロップダウンすると、ユーザーはメールを送信したすべてのアドレスのリストを見ることができます。私はそこにすべてのテキストを置き換えるのではなく、テキストフィールドにアドレスを追加するコンボボックスを欲しい。C#電子メールアドレスコンボボックス
たとえば、私はコンボボックスのリストに[email protected]、[email protected]、[email protected]という電子メールのリストを持っており、[email protected]はコンボボックスにあります。私がcboxのリストから[email protected]を選択すると、「[email protected]、[email protected]」となるcombobox.Textとしたいが、テキストは[email protected]となる。
This is the combobox: +----------------+ +----------------+ | [email protected] |V| | [email protected] |V| +----------------+ +----------------+ | [email protected] | | [email protected] | | [email protected] | trying to select this brings | [email protected] | | [email protected] | which is not desired | [email protected] | +----------------+ +----------------+ When someone clicks on [email protected] or [email protected] or [email protected] the editable field becomes that value. For example, after selecting [email protected] it will become +----------------+ | [email protected] |V| +----------------+ I want combobox to append values and not just select them. So I want it to show +------------------------------+ | [email protected], [email protected] |V| +------------------------------+ instead of just +----------------+ | [email protected] |V| +----------------+
は、私は(それがコンボボックス、ボタンとボタンでちょうど形だが、フォームのFormClosedイベントが、設定されているボタンのClickイベントが設定され、コンボボックスのイベントは、のSelectedIndexChangedとTextChangedが設定されている)、このコードを書いたが、それはのように動作しません。私が期待する。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
cboxFrom.Tag = string.IsNullOrEmpty(Settings.Default.emailFrom) ? "" : Settings.Default.emailFrom;
cboxFrom.Text = (string)cboxFrom.Tag;
if (Settings.Default.emailFroms == null)
Settings.Default.emailFroms = new System.Collections.Specialized.StringCollection();
//cboxFrom.DataSource = Settings.Default.emailFroms;
foreach (string s in Settings.Default.emailFroms)
cboxFrom.Items.Add(s);
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
Settings.Default.Save();
}
private void cboxFrom_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
ComboBox cbox = (ComboBox)sender;
string addr = (string)cbox.Items[cbox.SelectedIndex];
if (addr != null && cbox.Tag != null && !(cbox.Tag as string).Contains(addr))
{
if (cbox.Text.Trim().Length == 0)
cbox.Text = addr;
else
cbox.Text = cbox.Tag + ", " + addr;
cbox.Tag = cbox.Text;
}
else
cbox.Text = (string)cbox.Tag;
}
catch { }
}
private void cboxFrom_KeyPress(object sender, KeyPressEventArgs e)
{
ComboBox cbox = (ComboBox)sender;
cbox.Tag = cbox.Text;
}
private void button1_Click(object sender, EventArgs e)
{
string[] addrs = cboxFrom.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach(string s in addrs)
if(!Settings.Default.emailFroms.Contains(s.Trim()))
Settings.Default.emailFroms.Add(s);
}
}
私は何を達成しようとしているのか分かりません。それは非常にばかばかしいようです。 – V4Vendetta
アドレスをコンボボックスの編集可能なフィールドに置き換えるのではなく、アドレスを追加したいと思います。出来ますか? – Blablablaster
テキストボックスのような別のコントロールにそれらを追加しないでください。これは[email protected]に何が起こるのか混乱させます。リストから消えるか、クリックしたときに再び追加されます。これはどんな場合でもコンボボックスを使用する方法ではありません – V4Vendetta