I have GridgroupingControl with 2 columns (code,
Name) bind to a binding source, when I add a new row using the bindingsource. If
I save the empty new record I cannot get the CurrentCellValidating
to fire.
But if I enter values manually in
the new row CurrentCellValidating works perfectly.
Can you help me?
//Retrieved the currencylist
var x = DataModule.SharedInstance.CurrencyList;
//Binds the DataSet to the binding
source.
bindingSourceCurrencies.DataSource
= x;
//pass the binding source to the
GridgoupingControl
this.gridGCcurrencies.DataSource
= bindingSourceCurrencies;
//add
a new line to the BS which is reflect on
GridgroupingControl
private void toolStripButtonAdd_Click(object sender, EventArgs e)
{
bindingSourceCurrencies.AddNew();
bindingSourceCurrencies.ResetCurrentItem();
toolStripButtonAdd.Enabled = false;
}
//validate
the first column
void
gridGCcurrencies_CurrentCellValidating(object sender, GridTableControlCancelEventArgs e)
{
GridCurrentCell currentCell = this.gridGCcurrencies.TableControl.CurrentCell;
GridTableCellStyleInfo tableCellStyle = e.TableControl.GetTableViewStyleInfo(currentCell.RowIndex, currentCell.ColIndex);
if
(tableCellStyle.TableCellIdentity.Column != null &&
tableCellStyle.TableCellIdentity.Column.Name == "Code")
{
if (string.IsNullOrEmpty(currentCell.Renderer.ControlText.Trim()))
{
currentCell.SetError("Please
cannot be null");
}
}
}
//Saving
the changes to the backend
private void toolStripButtonSave_Click(object sender, EventArgs e)
{
JDSdb1.DataModule.SharedInstance.ApplyChanges();
toolStripButtonAdd.Enabled = true;
}
|
//Event triggering
gridGroupingControl1.SourceListListChangedCompleted += GridGroupingControl1_SourceListListChangedCompleted;
//Event customization
private void GridGroupingControl1_SourceListListChangedCompleted(object sender, TableListChangedEventArgs e)
{
if (e.ListChangedType == ListChangedType.ItemAdded)
{
int index = e.Table.Records.Count - 1;
//To set the newly added record as current record
e.Table.CurrentRecord = e.Table.Records[index];
//To set the column as current cell
e.Table.CurrentRecord.SetCurrent("Code");
//To trigger the CurrentCellValidating event.
gridGroupingControl1.TableControl.CurrentCell.Validate();
}
} |
|
//Event triggering
gridGroupingControl1.TableControlCurrentCellValidating += GridGroupingControl1_TableControlCurrentCellValidating;
//Event customization
private void GridGroupingControl1_TableControlCurrentCellValidating(object sender, GridTableControlCancelEventArgs e)
{
GridCurrentCell currentCell = this.gridGroupingControl1.TableControl.CurrentCell;
GridTableCellStyleInfo tableCellStyle = e.TableControl.GetTableViewStyleInfo(currentCell.RowIndex, currentCell.ColIndex);
if (tableCellStyle.TableCellIdentity.Column != null && tableCellStyle.TableCellIdentity.Column.Name == "Code")
{
if (string.IsNullOrEmpty(currentCell.Renderer.ControlText.Trim()))
{
currentCell.SetError("Please cannot be null");
// To restrict moving of current cell.
e.Inner.Cancel = true;
}
}
}
|
When using
(e.Inner.Cancel = true) the cell received the focus with the error which is perfect, if I try
to move to another cell on the same row the grid block me which is also perfect.
But if I
select a cell in another row I can bypass the validation.
see pdf
|
private void GridGroupingControl1_SourceListListChangedCompleted(object sender, TableListChangedEventArgs e)
{
if (e.ListChangedType == ListChangedType.ItemAdded)
{
int index = e.Table.Records.Count - 1;
e.Table.CurrentRecord = e.Table.Records[index];
e.Table.CurrentRecord.SetCurrent("Code");
gridGroupingControl1.TableControl.CurrentCell.IsModified = true;.
gridGroupingControl1.TableControl.CurrentCell.Validate();
}
} |
For the newly added row I have many columns
(Code, Name, Status, ConversionRate, Date)
The
validation works fine for the first column (Code), but when I move the next column
(Name) how do I get the validation event to fire.
Same thing
for every column on that new row they all have validations
Merci.
|
private void GridGroupingControl1_SourceListListChangedCompleted(object sender, TableListChangedEventArgs e)
{
if (e.ListChangedType == ListChangedType.ItemAdded)
{
int index = e.Table.Records.Count - 1;
e.Table.CurrentRecord = e.Table.Records[index];
foreach (GridColumnDescriptor column in this.gridGroupingControl1.TableDescriptor.Columns)
{
e.Table.CurrentRecord.SetCurrent(column.ToString());
gridGroupingControl1.TableControl.CurrentCell.IsModified = true;
gridGroupingControl1.TableControl.CurrentCell.Validate();
}
}
} |
|
gridGroupingControl1.TableControlCurrentCellMoved += GridGroupingControl1_TableControlCurrentCellMoved;
private void GridGroupingControl1_TableControlCurrentCellMoved(object sender, GridTableControlCurrentCellMovedEventArgs e)
{
if (isAdded && e.TableControl.CurrentCell.RowIndex == gridGroupingControl1.TableModel.RowCount )
{
e.TableControl.CurrentCell.IsModified = true;
e.TableControl.CurrentCell.Validate();
}
} |