This question is locked. New answers and comments are not allowed.
Hi All,
Loosing Template column data after adding new row in grid.
Here's my code for issue.
Here's C# Code :-
For more information please find attached screenshot.
Loosing Template column data after adding new row in grid.
Here's my code for issue.
<
telerik:RadGridView
x:Name
=
"radGridCustomColumns"
Margin
=
"0,0,0,10"
MaxHeight
=
"400"
HeaderRowStyle
=
"{StaticResource BoldHeaderStyle}"
RowIndicatorVisibility
=
"Collapsed"
telerik:StyleManager.Theme
=
"Windows7"
AlternateRowBackground
=
"#EBEFF3"
AlternationCount
=
"2"
ShowGroupPanel
=
"False"
GridLinesVisibility
=
"None"
Width
=
"Auto"
HorizontalAlignment
=
"Stretch"
VerticalAlignment
=
"Top"
ShowColumnFooters
=
"False"
CanUserInsertRows
=
"False"
IsReadOnly
=
"True"
ShowColumnHeaders
=
"True"
AutoGenerateColumns
=
"False"
Visibility
=
"Visible"
CanUserResizeColumns
=
"False"
CanUserFreezeColumns
=
"False"
IsFilteringAllowed
=
"False"
CanUserSortColumns
=
"False"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
Header
=
"Components"
DataMemberBinding
=
"{Binding Components}"
Width
=
"12*"
>
<
telerik:GridViewDataColumn.CellTemplate
>
<
DataTemplate
>
<
TextBlock
Text
=
"{Binding Components}"
Width
=
"100"
VerticalAlignment
=
"Top"
TextWrapping
=
"Wrap"
HorizontalAlignment
=
"Left"
ToolTipService.ToolTip
=
"{Binding Components}"
/>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellTemplate
>
</
telerik:GridViewDataColumn
>
<
telerik:GridViewDataColumn
Header
=
"UI Columns"
UniqueName
=
"UIColumns"
Width
=
"14*"
>
<
telerik:GridViewDataColumn.CellTemplate
>
<
DataTemplate
>
<
TextBox
Width
=
"150"
Height
=
"25"
VerticalAlignment
=
"Top"
TextWrapping
=
"Wrap"
Text
=
"{Binding UIColumns,Mode=TwoWay}"
HorizontalAlignment
=
"Left"
/>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellTemplate
>
</
telerik:GridViewDataColumn
>
<
telerik:GridViewDataColumn
UniqueName
=
"Action"
Width
=
"5*"
>
<
telerik:GridViewDataColumn.Header
>
<
TextBlock
Text
=
"Actions"
TextWrapping
=
"Wrap"
/>
</
telerik:GridViewDataColumn.Header
>
<
telerik:GridViewDataColumn.CellTemplate
>
<
DataTemplate
>
<
StackPanel
Orientation
=
"Horizontal"
VerticalAlignment
=
"Top"
HorizontalAlignment
=
"Center"
>
<
Image
Name
=
"imgAdd"
Source
=
"/QualityTrackingReportModule;component/Images/greenplus.png"
MouseLeftButtonDown
=
"imgAdd_MouseLeftButtonDown"
Cursor
=
"Hand"
Margin
=
"0,0,3,0"
Height
=
"16"
Width
=
"16"
/>
<
Image
Name
=
"imgEdit"
Source
=
"/QualityTrackingReportModule;component/Images/Edit.png"
Cursor
=
"Hand"
Margin
=
"0,0,3,0"
Height
=
"16"
Width
=
"16"
/>
<
Image
Name
=
"imgDelete"
Source
=
"/QualityTrackingReportModule;component/Images/Delete.png"
Cursor
=
"Hand"
Margin
=
"0,0,0,0"
Height
=
"16"
Width
=
"16"
/>
</
StackPanel
>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellTemplate
>
</
telerik:GridViewDataColumn
>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
namespace
QualityTrackingReportModule
{
public
partial
class
QTRMUICustomization : Page
{
public
QTRMUICustomization()
{
InitializeComponent();
radGridCustomColumns.EnableColumnVirtualization =
false
;
radGridCustomColumns.Width = App.Current.Host.Content.ActualWidth - 25;
ObservableCollection<CustomColumns> lst =
new
ObservableCollection<CustomColumns>();
lst.Add(
new
CustomColumns { Components =
"HDL"
, UIColumns =
"Custom"
});
lst.Add(
new
CustomColumns { Components =
"LDL"
, UIColumns =
"Custom"
});
lst.Add(
new
CustomColumns { Components =
"Systolic BP"
, UIColumns =
"Static"
});
radGridCustomColumns.ItemsSource = lst;
}
private
void
imgAdd_MouseLeftButtonDown(
object
sender, MouseButtonEventArgs e)
{
GridViewRow row = ((Image)sender).ParentOfType<GridViewRow>();
row.IsSelected =
true
;
object
newRow = radGridCustomColumns.Items.AddNew();
radGridCustomColumns.Items.Remove(newRow);
int
currentIndex = radGridCustomColumns.Items.IndexOf(radGridCustomColumns.SelectedItem);
((IList)radGridCustomColumns.ItemsSource).Insert(currentIndex + 1, newRow);
// Select the new row
radGridCustomColumns.SelectedItem = newRow;
radGridCustomColumns.Items.MoveCurrentTo(newRow);
}
}
public
class
CustomColumns
{
public
string
Components {
get
;
set
; }
public
string
UIColumns {
get
;
set
; }
}
}
For more information please find attached screenshot.