本文整理汇总了C#中System.Windows.Forms.DataGridView.EndEdit方法的典型用法代码示例。如果您正苦于以下问题:C# DataGridView.EndEdit方法的具体用法?C# DataGridView.EndEdit怎么用?C# DataGridView.EndEdit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.DataGridView
的用法示例。
在下文中一共展示了DataGridView.EndEdit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyFilter
/// <summary>
/// Allows to convert DataGridView rows to BindingSource filter
/// </summary>
/// <param name="bindingSource">target BindingSource</param>
/// <param name="dgv">source DataGridView</param>
public static void ApplyFilter(BindingSource bindingSource, DataGridView dgv)
{
dgv.EndEdit();
string filtertext = "";
dgv.Rows[0].Cells["AndOr"].Value = "";
foreach (DataGridViewRow row in dgv.Rows)
{
if (row.Cells["Field"].Value == null ||
row.Cells["Operator"].Value == null ||
row.Cells["Value"].Value == null)
continue;
string value = row.Cells["Value"].Value.ToString() == "@me"
? UserData.UserName
: row.Cells["Value"].Value.ToString();
filtertext += string.Format("{0} {1} {2} '{3}' ",
row.Cells["AndOr"].Value,
row.Cells["Field"].Value,
row.Cells["Operator"].Value,
value);
}
try
{
bindingSource.Filter = filtertext;
}
catch (Exception ex)
{
MessageBox.Show("Invalid query\r\n" + ex.Message, "Query error");
bindingSource.Filter = string.Empty;
}
}
示例2: AddFullSelect
/// <summary>
/// DataGridView添加全选
/// </summary>
/// <param name="dgv">DataGridView控件ID</param>
/// <param name="columnIndex">全选所在列序号</param>
public void AddFullSelect(DataGridView dgv, int columnIndex)
{
if (dgv.Rows.Count < 1)
{
return;
}
CheckBox ckBox = new CheckBox();
Rectangle rect = dgv.GetCellDisplayRectangle(1, -1, true);
ckBox.Size = new Size(dgv.Columns[1].Width - 12, 12); //大小
Point point = new Point(rect.X + 10, rect.Y + 3);//位置
ckBox.Location = point;
ckBox.CheckedChanged += delegate(object sender, EventArgs e)
{
for (int i = 0; i < dgv.Rows.Count; i++)
{
dgv.Rows[i].Cells[columnIndex].Value = ((CheckBox)sender).Checked;
}
dgv.EndEdit();
};
dgv.Controls.Add(ckBox);
}
示例3: ChildSavedata
/// <summary>
/// 通用保存数据
/// </summary>
/// <param name="dgv"></param>
/// <param name="Typename"></param>
public void ChildSavedata(DataGridView dgv,string Typename)
{
List<string> SqlLst = new List<string>();
int i = 0;
string sysid = "";
string matid = "";
string Sql = "";
string Copynum = "";
string Memo = "";
string strsql = "";
int Count = dgv.Rows.Count;
string matsysid = dgv_model.SelectedRows[0].Cells["sysid"].Value.ToString();
strsql = "delete T_ModelMats where modelsysid='" + matsysid + "' and Stype='" + Typename + "'";
SqlLst.Add(strsql);
for (i = 0; i < Count-1; i++)
{
//先结束边界,不然不能获取当前值
dgv.EndEdit();
sysid = dgv.Rows[i].Cells["sysid"].Value.ToString();
matid = dgv.Rows[i].Cells["物料编码"].Value.ToString();
if (matid == "") continue;
Copynum = dgv.Rows[i].Cells["平均复印张数"].Value.ToString();
Memo = dgv.Rows[i].Cells["备注"].Value.ToString();
Sql = "insert into T_ModelMats(modelsysid,Matid,Stype,CopyCount,memo) values " +
"('" + matsysid + "','" + matid + "','" + Typename + "','" + Copynum + "','" + Memo + "') ";
SqlLst.Add(Sql);
}
try
{
(new SqlDBConnect()).Exec_Tansaction(SqlLst);
MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
msm_MatsSelect_();
}
catch
{
MessageBox.Show("当前存在与该物料编码不对应的物料名,请检查后再保存!", "提示");
}
}
示例4: ParseGridAndCreateJavascriptData
/// <summary>
///
/// </summary>
public virtual string ParseGridAndCreateJavascriptData(DataGridView dataGridCurrent, string sJsDataTemplate, Form cMainForm, TabControl tabData)
{
string sReturnJavascript = sJsDataTemplate;
dataGridCurrent.EndEdit();
return (sReturnJavascript);
}
示例5: BatchDelete
/// <summary>
/// 批量删除数据
/// </summary>
/// <param name="dgv"></param>
/// <param name="opName">操作名</param>
/// <param name="tableName">表名</param>
/// <param name="key">主健</param>
/// <param name="checkName">选择控件名</param>
/// <param name="keyName">主键控件名</param>
private void BatchDelete(DataGridView dgv, string opName, string tableName, string key, string checkName, string keyName)
{
if (MessageBoxEx.Show("确认要删除选择的项吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
{
return;
}
dgv.EndEdit();
StringBuilder sbWhere = new StringBuilder();
foreach (DataGridViewRow dgvr in dgv.Rows)
{
object isCheck = dgvr.Cells[checkName].Value;
if (isCheck != null && (bool)isCheck)
{
if (sbWhere.Length > 0)
{
sbWhere.Append(",");
}
string name = CommonCtrl.IsNullToString(dgvr.Cells[keyName].Value);
if (name.Length > 0)
{
sbWhere.AppendFormat("'{0}'", name);
}
}
}
if (sbWhere.Length == 0)
{
DeleteDataGridViewRow(dgv, checkName);
return;
}
if (DBHelper.BatchDeleteDataByWhere(opName, GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.CommAccCode, tableName, string.Format("{0} in ({1})", key, sbWhere.ToString())))
{
DeleteDataGridViewRow(dgv, checkName);
}
else
{
MessageBoxEx.Show("删除失败");
}
}
示例6: commitNewRow
public void commitNewRow(DataGridView dgv)
{
dgv.NotifyCurrentCellDirty(true);
dgv.EndEdit();
dgv.NotifyCurrentCellDirty(false);
}
示例7: AddArticleToCheque
//.........这里部分代码省略.........
else
dRow["TOT"] = GetRoundedDose(startTotal);
index = cheque.Rows.IndexOf(dRow);
rowIsUpdated = true;
}
catch (Exception ex)
{
WriteLog(ex, MethodInfo.GetCurrentMethod().Name);
}
}
//Add new row
if (!rowIsUpdated)
{
//winapi.Funcs.OutputDebugString("J");
dRow = cheque.NewRow();
dRow["ORIGPRICE"] = article["PRICE"];
//C
string c = dRow["C"].ToString();
dRow.ItemArray = article.ItemArray;
dRow["C"] = long.Parse(c);
//TAX
try
{
index = Array.IndexOf<char>(AppConfig.TAX_MarketColumn, dRow["VG"].ToString()[0]);
}
catch { index = 0; }
if (index < 0)
index = 0;
char pch = AppConfig.TAX_AppColumn[index];
index = Array.IndexOf<char>(AppConfig.TAX_AppTaxChar, pch);
if (index >= 0)
{
dRow["VG"] = pch;
dRow["TAX_VAL"] = AppConfig.TAX_AppTaxRates[index];
dRow["USEDDISC"] = AppConfig.TAX_AppTaxDisc[index];
}
if (UserConfig.Properties[17] || startTotal == 0.0)
{
Request req = new Request(dRow, startTotal);
funcRezult = req.UpdateRowSource(chqDGW);
req.Dispose();
if (!funcRezult) return;
}
else
dRow["TOT"] = startTotal;
#region Sorting article by ID and adding
if (UserConfig.Properties[14] && cheque.Rows.Count != 0)
{
index = 0;
do
{
if (GetIDCode(cheque.Rows[index]["ID"]) < GetIDCode(dRow["ID"]))
index++;
else
break;
} while (cheque.Rows.Count > index);
cheque.Rows.InsertAt(dRow, index);
}
else
{
cheque.Rows.Add(dRow);
index = cheque.Rows.Count - 1;
}
#endregion
}
//winapi.Funcs.OutputDebugString("K");
if (rowIsUpdated)
index = dRow.Table.Rows.IndexOf(dRow);
chqDGW.CurrentCell = chqDGW.Rows[index].Cells["TOT"];
try
{
object uniqueKey = article["C"];
article = (artDGW.DataSource as DataTable).Rows.Find(uniqueKey);
if (article != null)
index = (artDGW.DataSource as DataTable).Rows.IndexOf(article);
else
{
artDGW.DataSource = artsTable;
article = artsTable.Rows.Find(uniqueKey);
index = artsTable.Rows.IndexOf(article);
}
artDGW.CurrentCell = artDGW.Rows[index].Cells[artDGW.Columns.GetFirstColumn(DataGridViewElementStates.Visible).Name];
}
catch { }
chqDGW.BeginEdit(true);
if (!UserConfig.Properties[22])
chqDGW.EndEdit();
//winapi.Funcs.OutputDebugString("E");
}
示例8: DeleteRow
/// <summary>
/// 删除DataGridView选择的行
/// </summary>
/// <param name="dgv">DataGridView</param>
/// <param name="dgvcc">选择的复选框</param>
void DeleteRow(DataGridView dgv, DataGridViewCheckBoxColumn dgvcc)
{
dgv.EndEdit();
for (int i = dgv.Rows.Count - 1; i >= 0; i--)
{
DataGridViewRow dgvr = dgv.Rows[i];
object check = dgvr.Cells[dgvcc.Name].Value;
if (check != null && (bool)check)
{
dgv.Rows.Remove(dgvr);
}
}
}
示例9: Varify
private void Varify(DataGridView dgv)
{
dgv.EndEdit();
error_privider.Clear();
string error_message = string.Empty;
Dictionary<string, List<DataGridViewRow>> dicCells = new Dictionary<string, List<DataGridViewRow>>();
foreach (DataGridViewRow row in dgv.Rows)
{
if (row.IsNewRow)
continue;
row.ErrorText = string.Empty;
string key = (row.Cells[0].Value + "") + "-" + (row.Cells[1].Value + "") + "-" + (row.Cells[2].Value + "");
if (key == "--")
{
error_message = "至少要有一個條件。\n";
continue;
}
if (!dicCells.ContainsKey(key))
dicCells.Add(key, new List<DataGridViewRow>());
dicCells[key].Add(row);
}
foreach (string key in dicCells.Keys)
{
if (dicCells[key].Count > 1)
{
error_message += "條件的組合重覆。";
}
}
error_privider.SetError(dgv, error_message);
}
示例10: UpdateGridRowCells
/// <summary>
/// void UpdateGridRowCells(DataGridView _grid)
/// Update the columns for the passed grid
/// </summary>
/// <param name="_grid"></param>
public static void UpdateGridRowCells(DataGridView _grid)
{
try
{
_grid.EndEdit();
for (int n = 0; n < _grid.RowCount; n++)
{
for (int m = 0; m < _grid.Columns.Count; m++)
{
_grid.UpdateCellValue(m, n);
}
}
}
catch (Exception ex)
{
CommonRoutines.Log("$E:" + moduleName + ".UpdateGridRowCells > " + ex.Message);
}
return;
}
示例11: SaveQuery
/// <summary>
/// Allows to convert datagridview to query list
/// </summary>
/// <param name="dgv">source</param>
/// <param name="filename">path to save</param>
public static void SaveQuery(DataGridView dgv, string filename)
{
dgv.EndEdit();
dgv.Rows[0].Cells["AndOr"].Value = string.Empty;
IEnumerable queryList = dgv.Rows
.Cast<DataGridViewRow>()
.Where(row => row.Cells["Field"].Value != null
&& row.Cells["Operator"].Value != null
&& row.Cells["Value"].Value != null)
.Select(row => new Query
{
AndOr = row.Cells["AndOr"].Value != null
? row.Cells["AndOr"].Value.ToString()
: "",
Field = row.Cells["Field"].Value.ToString(),
Operator = row.Cells["Operator"].Value.ToString(),
Value = row.Cells["Value"].Value.ToString()
})
.ToList();
using (var sw = new StreamWriter(Path.Combine(DirectoryPath, filename), false, Encoding.Default))
{
queryList.Serialize(sw);
}
}
示例12: Varify
private void Varify(DataGridView dgv)
{
dgv.EndEdit();
string error_message = string.Empty;
Dictionary<string, List<DataGridViewCell>> dicCells = new Dictionary<string, List<DataGridViewCell>>();
this.errorProvider1.Clear();
if (string.IsNullOrEmpty(this.cboSemester.Text))
this.errorProvider1.SetError(this.cboSemester, "必填。");
//if (this.dgvData.Rows.Count == 0 || (this.dgvData.Rows.Count == 1 && this.dgvData.Rows[0].IsNewRow))
//{
// errorProvider1.SetError(this.dgvData, "請設定資料再儲存。");
// return;
//}
foreach (string key in dicCells.Keys)
{
if (dicCells[key].Count > 1)
{
dicCells[key].ForEach(x => x.ErrorText = "次別重覆。");
}
}
foreach (DataGridViewRow row in dgv.Rows)
{
if (row.IsNewRow)
continue;
row.Cells[0].ErrorText = "";
row.Cells[1].ErrorText = "";
row.Cells[2].ErrorText = "";
string key = row.Cells[0].Value + "";
if (!dicCells.ContainsKey(key))
dicCells.Add(key, new List<DataGridViewCell>());
dicCells[key].Add(row.Cells[0]);
DateTime begin_date_time;
DateTime end_date_time;
if (!DateTime.TryParse(row.Cells[1].Value + "", out begin_date_time))
row.Cells[1].ErrorText = "開始時間格式錯誤。範例:2013/6/22 00:01";
if (!DateTime.TryParse(row.Cells[2].Value + "", out end_date_time))
row.Cells[2].ErrorText = "結束時間格式錯誤。範例:2013/7/31 23:59";
if (DateTime.TryParse(row.Cells[1].Value + "", out begin_date_time) && DateTime.TryParse(row.Cells[2].Value + "", out end_date_time))
{
if (begin_date_time >= end_date_time)
row.Cells[1].ErrorText = "開始時間不得大於或等於結束時間。";
}
}
foreach (DataGridViewRow row in this.dgvData.Rows)
{
if (row.IsNewRow)
continue;
DateTime begin_date_time_1;
DateTime end_date_time_1;
DateTime begin_date_time_2;
DateTime end_date_time_2;
foreach (DataGridViewRow row2 in this.dgvData.Rows)
{
if (row2.IsNewRow)
continue;
if (row.Index == row2.Index)
continue;
if (DateTime.TryParse(row.Cells[1].Value + "", out begin_date_time_1) && DateTime.TryParse(row.Cells[2].Value + "", out end_date_time_1) && DateTime.TryParse(row2.Cells[1].Value + "", out begin_date_time_2) && DateTime.TryParse(row2.Cells[2].Value + "", out end_date_time_2))
{
if ((begin_date_time_1 >= begin_date_time_2 && begin_date_time_1 <= end_date_time_2) || (begin_date_time_2 >= begin_date_time_1 && begin_date_time_2 <= end_date_time_1))
{
row.Cells[1].ErrorText = "開始時間重疊。";
row2.Cells[1].ErrorText = "開始時間重疊。";
}
if ((end_date_time_1 >= begin_date_time_2 && end_date_time_1 <= end_date_time_2) || (end_date_time_2 >= begin_date_time_1 && end_date_time_2 <= end_date_time_1))
{
row.Cells[2].ErrorText = "結束時間重疊。";
row2.Cells[2].ErrorText = "結束時間重疊。";
}
}
}
}
}
示例13: Edit
static void Edit(DataGridView grid, string text)
{
grid.BeginEdit(false);
grid.EditingControl.Text = text;
grid.EndEdit();
}
示例14: valida_vacios
public static Boolean valida_vacios(DataGridView dgv, String texto)
{
if (dgv.Rows.Count > 0)
{
DataGridViewCell dgc;
dgv.EndEdit();
dgc = dgv.Rows[dgv.Rows.Count - 1].Cells[texto];
if ((String)dgc.Value.ToString() == string.Empty)
{
MessageBox.Show("Debe tener un valor en: " + texto + ", por favor verifíquelo", "Error al llenar celdas", MessageBoxButtons.OK, MessageBoxIcon.Information);
return true;
}
else return false;
}
else return false;
}
示例15: AcceptChanges
public void AcceptChanges(DataGridView dataGridCurrent)
{
if (dataGridCurrent.IsCurrentCellDirty || dataGridCurrent.IsCurrentRowDirty)
{
dataGridCurrent.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
dataGridCurrent.EndEdit();
//dataGridCurrent.is
//DataTable table = dataGridCurrent.DataSource as DataTable;
//if (table.GetChanges() != null)
//{
// foreach (DataRow row in table.Rows)
// {
// row.AcceptChanges();
// }
//}
}