This question is locked. New answers and comments are not allowed.
I have a GridView in my xaml. I am planning on showing a nested GridView when the row is clicked on. I have a DataTemplate for that, located in my XAML Resources.
<DataTemplate x:Key="KeyTemplate">
<telerik:RadGridView x:Name="rgvKeyData"
CanUserFreezeColumns="False"
DataContext="{Binding}"
IsReadOnly="True"
RowIndicatorVisibility="Collapsed"
ShowGroupPanel="False" />
</DataTemplate>
I would like to add columns and rows to this GridView programmatically, in the .cs file, but I cannot access rgvKeyData in my code. Here is what I am trying to do in the C#... the two bold commented out lines are where I am trying to work with the GridView:
private void RefreshDataGrid(string pFieldNames, string pFieldValues)
{
var _KeyDataTemplate = Resources["KeyTemplate"] as DataTemplate;
var _Rows = new SortableCollectionView();
pFieldNames = " Columns:|" + pFieldNames;
pFieldValues = "Values:|" + pFieldValues;
var _FieldNamesList = pFieldNames.Split('|');
var _FieldValueList = pFieldValues.Split('|');
try
{
var i = 0;
while (i < _FieldNamesList.Length)
{
var _Col = new DataGridTextColumn
{
Header = _FieldNamesList[i],
Binding = new System.Windows.Data.Binding
{
Converter = new RowIndexConverter(),
ConverterParameter = _FieldNamesList[i]
}
};
//rgvKeyData.Columns.Add(_Col);
i++;
}
i = 0;
var _Row = new Row();
while (i < _FieldValueList.Length)
{
if (i < _FieldNamesList.Length)
{
_Row[_FieldNamesList[i]] = _FieldValueList[i];
}
i++;
}
_Rows.Add(_Row);
//rgvKeyData.ItemsSource = _Rows;
}
catch
{
//quiet Catch
}
}
I either need to be able to access the rgvKeyTemplate GridView in my cs code, or I need another way to do this. I am pretty new to Telerik controls. I understand how to do a DataTemplate for a nested GridView, but only when I know the Grid columns before runtime. I just don't know how to handle the DataTemplate at runtime.
<DataTemplate x:Key="KeyTemplate">
<telerik:RadGridView x:Name="rgvKeyData"
CanUserFreezeColumns="False"
DataContext="{Binding}"
IsReadOnly="True"
RowIndicatorVisibility="Collapsed"
ShowGroupPanel="False" />
</DataTemplate>
I would like to add columns and rows to this GridView programmatically, in the .cs file, but I cannot access rgvKeyData in my code. Here is what I am trying to do in the C#... the two bold commented out lines are where I am trying to work with the GridView:
private void RefreshDataGrid(string pFieldNames, string pFieldValues)
{
var _KeyDataTemplate = Resources["KeyTemplate"] as DataTemplate;
var _Rows = new SortableCollectionView();
pFieldNames = " Columns:|" + pFieldNames;
pFieldValues = "Values:|" + pFieldValues;
var _FieldNamesList = pFieldNames.Split('|');
var _FieldValueList = pFieldValues.Split('|');
try
{
var i = 0;
while (i < _FieldNamesList.Length)
{
var _Col = new DataGridTextColumn
{
Header = _FieldNamesList[i],
Binding = new System.Windows.Data.Binding
{
Converter = new RowIndexConverter(),
ConverterParameter = _FieldNamesList[i]
}
};
//rgvKeyData.Columns.Add(_Col);
i++;
}
i = 0;
var _Row = new Row();
while (i < _FieldValueList.Length)
{
if (i < _FieldNamesList.Length)
{
_Row[_FieldNamesList[i]] = _FieldValueList[i];
}
i++;
}
_Rows.Add(_Row);
//rgvKeyData.ItemsSource = _Rows;
}
catch
{
//quiet Catch
}
}
I either need to be able to access the rgvKeyTemplate GridView in my cs code, or I need another way to do this. I am pretty new to Telerik controls. I understand how to do a DataTemplate for a nested GridView, but only when I know the Grid columns before runtime. I just don't know how to handle the DataTemplate at runtime.