Report steps:
Expected behavior:
Observed behavior:
Extra detail:
In the method MasterGridViewTemplate.PasteDataToRow the next piece is code is located:
if (CurrentView.ViewTemplate.Columns[columnIndex].DataType == typeof(string))
{
if (column is GridViewTextBoxColumn viewTextBoxColumn && viewTextBoxColumn.MaxLength > 0 && rowData[rowIndex].Length > viewTextBoxColumn.MaxLength)
obj = rowData[rowIndex].Substring(0, viewTextBoxColumn.MaxLength);
}
Hello, Martin,
I was able to reproduce the described behavior if there is MaxLength set to the respective column for the DataTable, but not to the respective column in RadGridView. Since the DataTable can't accept text longer than the maximum, in a normal situation it is not possible to set a value to the DataTable that violates the maximum:
The above error is handled and the user doesn't see the message. However, RadGridView offers the DataError event which is expected to be fired in this situation if the notifications are enabled. As a result, the user can be notified if this is the required behavior:
public RadForm1()
{
InitializeComponent();
DataTable dt = new DataTable();
dt.Columns.Add("Title");
dt.Columns["Title"].MaxLength = 10;
dt.Rows.Add("test");
this.radGridView1.DataSource = dt;
GridViewTextBoxColumn titleColumn = this.radGridView1.Columns["Title"] as GridViewTextBoxColumn;
// titleColumn.MaxLength = 10;
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.ClipboardPasteMode = GridViewClipboardPasteMode.EnableWithNotifications;
this.radGridView1.DataError += radGridView1_DataError;
}
private void radGridView1_DataError(object sender, GridViewDataErrorEventArgs e)
{
RadMessageBox.Show(e.Exception.Message);
}
An alternative approach is to specify the GridViewTextBoxColumn.MaxLength and thus the pasted value will be trimmed:
DataTable dt = new DataTable();
dt.Columns.Add("Title");
dt.Columns["Title"].MaxLength = 10;
dt.Rows.Add("test");
this.radGridView1.DataSource = dt;
GridViewTextBoxColumn titleColumn = this.radGridView1.Columns["Title"] as GridViewTextBoxColumn;
titleColumn.MaxLength = 10;
This is the achieved result:
Please give this approach a try and see how it works for your scenario.
Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.