本文整理汇总了C#中System.Windows.Forms.DataGridViewCellValidatingEventArgs类的典型用法代码示例。如果您正苦于以下问题:C# DataGridViewCellValidatingEventArgs类的具体用法?C# DataGridViewCellValidatingEventArgs怎么用?C# DataGridViewCellValidatingEventArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataGridViewCellValidatingEventArgs类属于System.Windows.Forms命名空间,在下文中一共展示了DataGridViewCellValidatingEventArgs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: dataGridView1_CellValidating
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
// Validate that the content length will fit into the DataSet.
if (dataGridView1.IsCurrentCellDirty)
{
int maxLength = northwindDS.Tables["Customers"].Columns[e.ColumnIndex].MaxLength;
if (e.FormattedValue.ToString().Length > maxLength)
{
String error = "Column value cannot exceed " + maxLength.ToString(System.Globalization.CultureInfo.CurrentUICulture) + " characters.";
// Show error icon/text since the value cannot fit.
DataGridViewCell c = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
c.ErrorText = error;
e.Cancel = false;
}
else
{
// Clear the error icon/text.
DataGridViewCell c = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
if (c.ErrorText != String.Empty)
c.ErrorText = String.Empty;
}
}
}
示例2: dataGridView1_CellValidating
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].Name == "IpColumn")
{
if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
{
dataGridView1.Rows[e.RowIndex].ErrorText = "请输入IP地址.";
MessageBox.Show(dataGridView1.Rows[e.RowIndex].ErrorText);
e.Cancel = true;
return;
}
IPAddress ip;
if (!IPAddress.TryParse(e.FormattedValue.ToString(), out ip))
{
dataGridView1.Rows[e.RowIndex].ErrorText = "请输入正确的IP地址,如192.168.1.1";
MessageBox.Show(dataGridView1.Rows[e.RowIndex].ErrorText);
e.Cancel = true;
}
}
if (dataGridView1.Columns[e.ColumnIndex].Name == "SecretKeyColumn")
{
if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
{
dataGridView1.Rows[e.RowIndex].ErrorText = "请输入SecretKey.";
MessageBox.Show(dataGridView1.Rows[e.RowIndex].ErrorText);
e.Cancel = true;
return;
}
}
}
示例3: dataGridView1_CellValidating
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
// http://www.codeproject.com/Questions/206915/What-is-the-difference-between-DataTable-DataSet-a
// script: error JSC1000: No implementation found for this native method, please implement [System.Windows.Forms.DataGridViewCellValidatingEventArgs.get_ColumnIndex()]
Console.WriteLine(new { e.ColumnIndex, e.RowIndex });
if (e.ColumnIndex == 0)
{
var i = 0;
// X:\jsc.svn\examples\javascript\Test\TestIntTryParse\TestIntTryParse\Application.cs
var value =
(string)e.FormattedValue;
Console.WriteLine(new { e.ColumnIndex, e.RowIndex, value });
var ok = int.TryParse(value, out i);
if (ok)
{
this.dataGridView1[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.White;
return;
}
Console.WriteLine(new { e.ColumnIndex, e.RowIndex, value, ok });
// { ColumnIndex = 0, RowIndex = 2, value = u, ok = false }
this.dataGridView1[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Yellow;
e.Cancel = true;
}
}
示例4: dataGridView1_CellValidating
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if ((m_OldValue != null) && (!m_OldValue.Equals(e.FormattedValue)))
m_DataChanged = true;
m_OldValue = null;
}
示例5: GRD_CellValidating
protected virtual void GRD_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (GRD.IsCurrentCellDirty)
{
m_GanttControl.HistorySetUndoPoint();
}
}
示例6: dataGridView1_CellValidating
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
switch (e.ColumnIndex)
{
case 1:
{
int i;
if (int.TryParse(e.FormattedValue.ToString(), out i))
if (i < 0)
{
e.Cancel = true;
dataGridView1.Rows[e.RowIndex].ErrorText = "开始时间必须是非负数";
}
}
break;
case 2:
{
int i;
if (int.TryParse(e.FormattedValue.ToString(), out i))
if (i <= 0)
{
e.Cancel = true;
dataGridView1.Rows[e.RowIndex].ErrorText = "运行时间必须是正数";
}
}
break;
default:
break;
}
}
示例7: dataGridViewSk_CellValidating
private void dataGridViewSk_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
try
{
if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
return;
if (dataGridViewSk.Rows[e.RowIndex].IsNewRow || e.ColumnIndex < 4)
return;
var value = e.FormattedValue.ToString();
int number;
bool result = Int32.TryParse(value, out number);
if (result)
{
// Alt er OK!
Log.d("Endret krav til " + number);
}
else
{
// Format feil!
if (value == null) value = "";
dataGridViewSk.Rows[e.RowIndex].ErrorText = "Feil format i krav. Må være hele ikke-negative tall."; //error massage
Log.n("Feil format i krav. Må være hele ikke-negative tall.", Color.Red);
e.Cancel = true;
}
}
catch (Exception ex)
{
Log.Unhandled(ex);
dataGridViewSk[e.ColumnIndex, e.RowIndex].Value = "0";
}
}
示例8: dataGridViewDetail_CellValidating
private void dataGridViewDetail_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (e.FormattedValue == null || e.FormattedValue.ToString().Length == 0)
return;
switch (e.ColumnIndex)
{
case 0:
string code = e.FormattedValue.ToString();
Tool t = SystemHelper.TMSContext.Tools.FirstOrDefault(s => s.Code == code);
if (t == null)
{
e.Cancel = true;
}
else
{
dataGridViewDetail.Rows[e.RowIndex].Cells["ItemName"].Value = t.Name;
dataGridViewDetail.Rows[e.RowIndex].Cells["ItemDimensions"].Value = t.Dimensions;
}
break;
case 1:
decimal quantity = 0;
if (!decimal.TryParse(e.FormattedValue.ToString(), out quantity))
e.Cancel = true;
break;
}
}
示例9: dataGridView_CellValidating
private void dataGridView_CellValidating( object sender, DataGridViewCellValidatingEventArgs e )
{
if ( !ignoreChanges &&
CellValidating != null )
{
CellValidating( this, e );
}
}
示例10: dataGridView1_CellValidating
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (int.Parse((string)e.FormattedValue) > 65535)
{
e.Cancel = true;
MessageBox.Show("输入值超出限定!");
}
}
示例11: ValidateRequiredGridCells
public static void ValidateRequiredGridCells(IWin32Window owner,
ref DataGridView gridview,
ref string msg,
ref DataGridViewCellValidatingEventArgs e,
bool showMessageBox)
{
DataGridViewRow row = gridview.Rows[e.RowIndex];
if (row.DataGridView.IsCurrentRowDirty)
{
#region Validate each cell in row
foreach (DataGridViewCell cell in row.Cells)
{
bool isNotValid;
if (e.ColumnIndex == cell.ColumnIndex)
{
isNotValid = e.FormattedValue.Equals(string.Empty);
}
else
{
isNotValid = cell.FormattedValue.Equals(string.Empty);
}
if (isNotValid)
{
cell.ErrorText = "Can't be Empty";
string column = gridview.Columns[cell.ColumnIndex].HeaderText;
if (msg.Length == 0)
{
msg += "- " + column + ": " + cell.ErrorText;
}
else
{
msg += "\n- " + column + ": " + cell.ErrorText;
}
}
else
{
cell.ErrorText = string.Empty;
}
}
#endregion
if (showMessageBox && msg.Length > 0)
{
e.Cancel = true;
MessageBox.Show(owner, msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
foreach (DataGridViewCell cell in row.Cells)
{
cell.ErrorText = String.Empty;
}
}
}
示例12: dataGridView1_CellValidating
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
int planno = System.Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["planno_setting"].Value);
if (planno < 0 || planno > 31)
{
e.Cancel = true;
MessageBox.Show("planno 必需介於0~31之間");
}
}
示例13: gvData_CellValidating
private void gvData_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (e.RowIndex >= 0 && e.ColumnIndex == 3)
{
obj = (BindingSource)gvData.DataSource;
SimpleData tranTemp = (SimpleData)obj.Current;
tranTemp.Vi = e.FormattedValue.ToString();
obj.List[e.RowIndex] = tranTemp;
}
}
示例14: dgvPodaci_CellValidating
private void dgvPodaci_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (dosloDoPromjene())
switch (MessageBox.Show("Želite li pohraniti promjene?", "Informacija...", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
{
case DialogResult.Yes:
spremiPromjene();
break;
}
}
示例15: dataGridView1_CellValidating
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
ushort hex;
switch (e.ColumnIndex)
{
case 2:
e.Cancel = !ushort.TryParse(e.FormattedValue.ToString(), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out hex);
break;
}
}