private void buttonEdit_Click(object sender, EventArgs e) { errorProvider1.Clear(); foreach (String head in pack.headers) { int index = pack.GetPackIndexByName(head); String value = getControlValue(panelEditZone.Controls[head] as IAutoControl); String matchstr = ""; String hintstr = ""; if (pack.dataTypes[index] == "int") { matchstr = @"^(-)?\d+$"; hintstr = "只能是整数"; } else if (pack.dataTypes[index] == "char") { matchstr = "^.{0," + pack.dataSizes[index] + "}$"; hintstr = String.Format("只能是字符串,且最大长度为{0}", pack.dataSizes[index]); } if (!Regex.IsMatch(value, matchstr)) { errorProvider1.SetError(panelEditZone.Controls[head], hintstr); return; } if (value.IndexOf('\n') >= 0) { errorProvider1.SetError(panelEditZone.Controls[head], "数据中有回车"); return; } } bool needupdatename = false; foreach (String head in pack.headers) { int index = pack.GetPackIndexByName(head); String value = getControlValue(panelEditZone.Controls[head] as IAutoControl); if (value != pack.data[selectId][index]) { pack.EditPackData(selectId, head, value); if (index == nameIndex) //名称键更新需要刷新列表 { needupdatename = true; } } } if (needupdatename) { refreshList(selectId); } }