我有字符串的列表框。當我選擇其中一個字符串時,我將它分開。C#,將值發送到文本框
我想發送到textboxes
該字符串的拆分值。如何將值發送到文本框?
我有這樣的C#代碼:
private void button8_Click(object sender, EventArgs e)
{
string Code;
string Name;
string PName;
string Cost;
string Num;
string Level;
using (var streamReader = new StreamReader(filePath, Encoding.Default))
{
if (!streamReader.EndOfStream)
{
Items.Add(streamReader.ReadLine());//list Items
}
}
string z = listBox1.SelectedItem.ToString();
string[] words = x.Split(',');
foreach (string word in words)
{
if (words.Length == 6)
{
Code = words[0];
Name = words[1];
PName = words[2];
Cost = words[3];
Num = words[4];
Level = words[5];
}
}
textBox1.Text = Code; //This does not send anything to the textbox
textBox2.Text = Name;
textBox3.Text = PName;
textBox4.Text = Cost;
textBox5.Text = Num;
textBox6.Text = Level;
using (var streamWriter = new StreamWriter(
filePath, false, Encoding.Default))
{
foreach (string op in Items)
{
streamWriter.WriteLine(op);
}
}
}
的C#代碼,不會textBox1.Text = Code;
不發送任何文字文本框,我如何分配一個字符串的文本框?
你應該命名你的控件。 – SLaks
你有什麼錯誤? – rohit89
你得到什麼確切的錯誤?它看起來像你的分割失敗,你會把默認值,但String.Empty應該罰款TextBox.Text ... – AlG