【发布时间】:2021-07-22 16:55:33
【问题描述】:
我正在用 C# 编写一个与足球相关的项目 winForms。我正在尝试制作一个打开另一个窗口的更新按钮。 这是我的课
public class Match
{
public string team1 { get; set; }
public string team2 { get; set; }
public string pariu { get; set; }
public float cota { get; set; }
public DateTime data { get; set; }
}
这是在 Form1 中
List<Match> m = new List<Match>();
//UPDATE
private void btEdit_Click(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count != 0)
{
Match p = m.ElementAt(listView1.SelectedIndices[0]);
Form2 edit = new Form2(p);
DialogResult dialogResult = edit.ShowDialog();//this is everytime = cancel
if (dialogResult == DialogResult.OK)
{
PopulateListView();//so this never happens
}
}
}
这是form2
private void button2_Click(object sender, EventArgs e)
{
this.Close();//cancel
}
private void button1_Click(object sender, EventArgs e)
{
match.team1 = textBox1.Text;
match.team2 = textBox2.Text;
float.TryParse(textBox3.Text, out float value);
match.cota = value;
this.Close();//save edit
}
为什么我每次更新我的 listView 中的内容时都会得到 showDialog = 'Cancel'?
【问题讨论】:
-
你在做 Instat 吗?
-
@Kamiky 不,这只是一个大学项目,我正在尝试为足球比赛做一个投注平台。
-
您可以使用其
DialogResult属性直接将DialogResult设置为按钮。单击 Button 时,它还定义了 Dialog 的结果。 -- 使用 DialogResult 时删除Close(),因为设置它也会关闭 Dialog。