The grid is being initialized with a "BillingItem" object, which contains properties SLA (String) and AvailableSLAs (List<SLA>).
The GridViewComboBoxColumn DataMemberBinding is set to the BillingItem.SLA, while the ItemsSourceBinding is set to the BillingItem.AvailableSLAs.
XAML
<
telerik:RadGridView
Name
=
"rgvProductLines"
Grid.Row
=
"2"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
CanUserFreezeColumns
=
"False"
CanUserReorderColumns
=
"False"
SelectionMode
=
"Extended"
ShowGroupPanel
=
"False"
RowDetailsVisibilityMode
=
"Visible"
IsFilteringAllowed
=
"False"
EditTriggers
=
"CellClick"
Height
=
"510"
Width
=
"1160"
MinHeight
=
"510"
MinWidth
=
"1160"
ShowInsertRow
=
"True"
CanUserSortColumns
=
"False"
AutoGenerateColumns
=
"False"
>
<telerik:RadGridView.Columns>
<telerik:GridViewComboBoxColumn
UniqueName
=
"SLA"
Header
=
"SLA"
DataMemberBinding
=
"{Binding SLA, Mode=TwoWay, ValidatesOnExceptions=True}"
ItemsSourceBinding
=
"{Binding AvailableSLAs}"
SelectedValueMemberPath
=
"Number"
DisplayMemberPath
=
"Description"
/>
<telerik:GridViewComboBoxColumn
UniqueName
=
"Obligation"
Header
=
"Obligation"
DataMemberBinding
=
"{Binding Obligation, Mode=TwoWay, ValidatesOnExceptions=True}"
ItemsSourceBinding
=
"{Binding AvailableObligations}"
SelectedValueMemberPath
=
"Number"
DisplayMemberPath
=
"Number"
/>
<!--other fields that are not relevant-->
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
During the PastingCellClipboardContent event for the SLA field of each Row being pasted in, the AvailableSLA is being set to an appropriate list of SLA objects. The SLA field is then being set to "Cell.Value.ToString().Trim()" in order to remove any extra spaces that the Excel data may contain so that it can find a match properly.
When debugging the code, the AvailableSLA field contains the 2 or 3 SLA objects that it should. However, the SLA field is initially being set to the correct value when stepping through line by line, but then is being set to Null afterwards by some other process (even though no other code updates in my project sets a value to the SLA property).
Please help!
11 Answers, 1 is accepted
Would you share the implementation of your PastingCellClipboardContent event ? How do you set the value for the property of GridViewComboBoxColumn ? Does the source of the column contain the value you want to set on pasting ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
void rgvProductLines_PastingCellClipboardContent(Object sender, GridViewCellClipboardEventArgs e)
{
// Get Current Record (Row)
agBillingItem Row = cellInfo.Item as agBillingItem;
// Determine Cell Currently Being Pasted
switch (e.Cell.Column.UniqueName)
{
String TempString = "";
case "SLA":
// Check for Length Error
if (e.Value.ToString().Trim().Length > 20)
{
TempString = TempString.Substring(0, 20).Trim();
}
Row.AvailableSLAs = SLAs // Page level variable (List<
SLA
> that contains AvailableSLAs to use for ItemsSourceBinding
Row.SLA = TempString
// Cell.Value = TempString; (I have tried this also with no success)
break;
// similar case statements with trimming done for other fields pasted in from Excel...
}
}
The source of the column (List<SLA> objects) contains for this test scenario 2 items:
1) Val = "104FSC110110000", Name = "Rejects and Adjustments"
2) Val = "104FSC180110000", Name = "Other"
The data being pasted in from Excel matches option #1 above ("104FSC110110000")
The AvailableSLA property is being set correctly and contains the 2 options, however the SLA property ends up as Null.
I have tested the behavior in our demos, but still I was not able to reproduce the same issue. Once I pasted a value into an item (the value must be present in the source of the column), it is updated right away. Would you verify whether the setter of the SLA property of your item is called and the value is updated properly at this time ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Is there an event that Is run after the entire Row has been pasted in, like RowValidating or something that may be causing this?
The SLA and AvailableSLA values are persisted correctly at first. Then it seems like the Row is displayed and the AvailableSLA values are requested (using "Get" to presumably use as reference for the items in the dropdown).
It then does the GetErrors check, finds no errors, and then proceeds to set SLA to null.
It's weird and I'm really not sure why this is happening.
SelectedValueMemberPath
=
"Number"
DisplayMemberPath
=
"Description"
...to...
SelectedValueMemberPath
=
"Number"
DisplayMemberPath
=
"Number"
...it started showing the values for the SLA column. This is not ideal to display the numeric code instead of the text description, but will work as a workaround for the time being.
However, if the SLA values is not a valid option from the AvailableSLAs List, the 1st item in the ComboBox is being displayed (in fact, the SLA property is set to the value of the 1st item in the ComboBox.
I need this to display as blank or show the field framed in red to identify an error.
I tried setting SLA = "" if the value does not exist in the AvailableSLAs List, but this did not make any difference.
It would be great if you could send a sample project illustrating your exact settings and implementation. Thus I would be able to suggest an appropriate solution, not just guessing for one.
Thank you in advance for your cooperation.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Please email me at mdecap@arcticit.com so that I can send you a zipped version of my project.
This function is called during the
void rgvProductLines_PastingCellClipboardContent(Object sender, GridViewCellClipboardEventArgs e)
{
// Get Current Record (Row)
GridViewCellInfo cellInfo = e.Cell as GridViewCellInfo;
agBillingItem Row = cellInfo.Item as agBillingItem;
// Determine Cell Currently Being Pasted
switch (cellInfo.Column.UniqueName)
{
case "SLA":
// Cleanse SLA
CleanseSLA(e, Row);
break;
}
}
public void CleanseSLA(GridViewCellClipboardEventArgs Cell, agBillingItem Row)
{
// Create Objects
Boolean MatchFound = false;
String TempString = Cell.Value.ToString().Trim();
// Check for Length Error
if (TempString.Length > SLALength)
{
// Trim
TempString = TempString.Substring(0, SLALength).Trim();
}
// Filter SLAs
FilterSLAs(Row);
// Loop through AvailableSLAs
//TODO: Not setting invalid SLA to blank
foreach (agSLA sla in Row.AvailableSLAs)
{
// Check if SLA is in AvailableSLA List
if (TempString == sla.Number)
{
// Update Value
Row.SLA = TempString;
// Update Flag
MatchFound = true;
}
}
// Check for Match
if (MatchFound != true)
{
// Reset SLA Field
Row.SLA = "";
}
}
I am checking to see if the Cell.Value being pasted in (trimmed) exists in the AvailableSLAs List.
I added some additional code to set the Row.SLA = "" in an attempt to have the GridViewComboBoxColumn for the row to dispaly blank (ie not match was found). I also tried to set Cell.Value = "", but this had the same result.
The result being that the SLA field is set to "", but the SLA is being set to the 1st item in the ComboBox after the Row pasting is completed.