This is a migrated thread and some comments may be shown as answers.

Copying cell content problem

6 Answers 258 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Oliver
Top achievements
Rank 1
Oliver asked on 11 Jul 2011, 09:45 PM
Hi,

I'm using VS2008 and Telerik V2010.3.1314.35 and I have a RadGridView with Date, Time and string column and I don't know why but when I try to copy cell content of cell type other that string, I have an error...

When I copy cell content of a data cell type other than string, "e.Value" always equal null....

How I can handle any cell data type when I try to copy a cell content???

Thank's

 

private void SignCtxVisitsGrid_CopyingCellClipboardContent(object sender, GridViewCellClipboardEventArgs e)

 

{

e.Cancel =

false;

 

 

if (mSelectedCell != null && mSelectedCell.Column == e.Cell.Column)

 

{

 

try

 

{

System.Windows.Forms.

Clipboard.SetText(e.Value as string);

 

}

 

catch (Exception exc)

 

{

}

}

 

else

 

{

e.Cancel =

true;

 

}

}

6 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 13 Jul 2011, 08:27 AM
Hello Oliver,

I have tried to reproduce the issue you reported, but unfortunately without any success. May you take a look at the sample attached to verify whether there are any misunderstandings or if you could reproduce the behavior on it ?
 

All the best,
Maya
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Oliver
Top achievements
Rank 1
answered on 14 Jul 2011, 07:27 PM
Hi,

I forgot to tell you, the problem seems to occur only with column who have a converter...
I have multiple datetime fields and for each field, I separate them into 2 columns...

e.Value return null in this situation

Thank's
0
Maya
Telerik team
answered on 15 Jul 2011, 08:41 AM
Hi Oliver,

May you provide a bit more details on the converter you are using ? How is it implemented ? Generally, any additional information and code-snippets would be helpful.

Best wishes,
Maya
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Oliver
Top achievements
Rank 1
answered on 15 Jul 2011, 02:17 PM
Ok,

like I said, in the CopyToCliboardevent, all columns using a converter return null in e.Value...

here is the XAML part of my grid and the map key for the converters:

 

 

<helper:HospitalDate x:Key="hospitalDateConverter" />

 

 

 

<helper:HospitalTime x:Key="hospitalTimeConverter" />

 

 

<telerik:RadGridView IsSynchronizedWithCurrentItem="True" Name="SignCtxVisitsGrid" Margin="6" Height="Auto" Width="Auto" IsReadOnly="True" SelectionMode="Single" RowIndicatorVisibility="Collapsed" AutoGenerateColumns="False" ShowGroupPanel="False" SelectionChanged="SignCtxVisitsGrid_SelectionChanged" RowLoaded="SignCtxVisitsGrid_RowLoaded" Style="{DynamicResource REF-RadGridViewStyle-Dark}" SelectionUnit="FullRow" CopyingCellClipboardContent="SignCtxVisitsGrid_CopyingCellClipboardContent" CurrentCellChanged="SignCtxVisitsGrid_CurrentCellChanged" GotFocus="SignCtxSearchExpander_GotFocus" LostFocus="SignCtxSearchExpander_LostFocus" PreviewKeyDown="SignCtxVisitsGrid_PreviewKeyDown" DataLoaded="SignCtxVisitsGrid_DataLoaded">

 

 

 

<telerik:RadGridView.Columns>

 

 

 

<telerik:GridViewDataColumn Name="SignCtxVisitsGridColUrgent" UniqueName="IsUrgent" Header="{StaticResource Urgent}" HeaderTextAlignment="Center" TextAlignment="Center" />

 

 

 

<telerik:GridViewDataColumn Name="SignCtxVisitsGridColTranscriptionDate" DataMemberBinding="{Binding Path=TranscriptionDate, Converter={StaticResource hospitalDateConverter}}" Header="{StaticResource TranscriptionDate}" HeaderTextAlignment="Center" TextAlignment="Center" />

 

 

 

<telerik:GridViewDataColumn Name="SignCtxVisitsGridColTranscriptionTime" DataMemberBinding="{Binding Path=TranscriptionDate, Converter={StaticResource hospitalTimeConverter}}" Header="{StaticResource TranscriptionTime}" HeaderTextAlignment="Center" TextAlignment="Center" IsFilterable="False" />

 

 

 

<telerik:GridViewDataColumn Name="SignCtxVisitsGridColDictationDate" DataMemberBinding="{Binding Path=DictationDate, Converter={StaticResource hospitalDateConverter}}" Header="{StaticResource DictationDate}" HeaderTextAlignment="Center" TextAlignment="Center" />

 

 

 

<telerik:GridViewDataColumn Name="SignCtxVisitsGridColDictationTime" DataMemberBinding="{Binding Path=DictationDate, Converter={StaticResource hospitalTimeConverter}}" Header="{StaticResource DictationTime}" HeaderTextAlignment="Center" TextAlignment="Center" IsFilterable="False" />

 

 

 

<telerik:GridViewDataColumn Name="SignCtxVisitsGridColExamDate" DataMemberBinding="{Binding Path=ExamDate, Converter={StaticResource hospitalDateConverter}}" Header="{StaticResource ExamDate}" HeaderTextAlignment="Center" TextAlignment="Center" />

 

 

 

<telerik:GridViewDataColumn Name="SignCtxVisitsGridColExamTime" DataMemberBinding="{Binding Path=ExamDate, Converter={StaticResource hospitalTimeConverter}}" Header="{StaticResource ExamTime}" HeaderTextAlignment="Center" TextAlignment="Center" IsFilterable="False" />

 

 

 

<telerik:GridViewDataColumn Name="SignCtxVisitsGridColVisitNumber" UniqueName="VisitNumber" Header="{StaticResource VisitNumber}" />

 

 

 

<telerik:GridViewDataColumn Name="SignCtxVisitsGridColId" UniqueName="PatientMRN" Header="{StaticResource Id}" />

 

 

 

<telerik:GridViewDataColumn Name="SignCtxVisitsGridColPatient" UniqueName="PatientName" Header="{StaticResource Patient}" />

 

 

 

<telerik:GridViewDataColumn Name="SignCtxVisitsGridColSecretary" UniqueName="TranscriptionistName" Header="{StaticResource Secretary}" />

 

 

 

<telerik:GridViewDataColumn Name="SignCtxVisitsGridColInterpretor" UniqueName="InterpreterName" Header="{StaticResource Interpretor}" />

 

 

 

<telerik:GridViewDataColumn Name="SignCtxVisitsGridColDepartment" UniqueName="DepartmentName" Header="{StaticResource Department}" />

 

 

 

</telerik:RadGridView.Columns>

 

 

 

</telerik:RadGridView>

Here is the converters (hospitalDateConverter and hospitalTimeConverter):

 

    [ValueConversion(typeof(DateTime), typeof(string))]
    public class HospitalDate : IValueConverter
    {
        #region IValueConverter interface implementation.
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || !(value is DateTime))
            {
                return "";
            }

            if ((DateTime)value == DateTime.MinValue)
            {
                return "";
            }

            return ((DateTime)value).ToString("yyyy'-'MM'-'dd");
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return "";
        }
        #endregion
    }

    [ValueConversion(typeof(DateTime), typeof(string))]
    public class HospitalTime : IValueConverter
    {
        #region IValueConverter interface implementation.
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || !(value is DateTime))
            {
                return "";
            }

            return ((DateTime)value).ToString("HH':'mm");
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return "";
        }
        #endregion
    }

Here is the CopyToClipboard event code:

 

 

private void SignCtxVisitsGrid_CopyingCellClipboardContent(object sender, GridViewCellClipboardEventArgs e)

 

{

e.Cancel =

false;

 

 

if (mSelectedCell != null && mSelectedCell.Column == e.Cell.Column)

 

{

 

try

 

 

 

 

 

{

System.Windows.Forms.

Clipboard.SetText(e.Value as string);

 

}

 

catch (Exception exc)

 

{

}

}

 

else

 

 

 

 

 

{

e.Cancel =

true;

 

}

}

0
Maya
Telerik team
answered on 20 Jul 2011, 08:19 AM
Hello Oliver,

I have tested the case with defining the converters you provided. However, again I was not able to reproduce the issue. May you take a look at the sample attached ? Am I missing something ? Are you able to get the same behavior on this very same project  ?
 

Regards,
Maya
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Oliver
Top achievements
Rank 1
answered on 20 Jul 2011, 07:23 PM
Maya,

unfortunatly the problem was on my side :( Just adding ClipboardCopyMode="Cells" solved my issue!!!!!!!!!!!!!!!!!!

Thank's
Tags
GridView
Asked by
Oliver
Top achievements
Rank 1
Answers by
Maya
Telerik team
Oliver
Top achievements
Rank 1
Share this question
or