Hi,
I have asked this question sometime back. But still struggling to find out the answer.... I am not sure whether I was clear to put my question. Thats why I am putting some code snippet as well, so that i makes more sense.
Problem: I want RadGridView configurable (where user can add
new row, delete row and edit the data) and on save button click
everything should be saved in the database. I have a situation where I
need to create an empty DataTable with different columns (depending on
user input). And then enter values under those columns and then on click
on save need to save value in the database. I am able to bind DataTable
to RadGridView (I can see all the column names and data rows if there is
already some data in the DataTable in the grid) but NOT able to add
(enter) or delete any row at the run time from RadGridView. I have set
"True" value for CanUserDeleteRows and CanUserInsertRows. I am not sure
where I am going wrong. I am implement INotifyPropertyChanged in my
ViewModel class.
My code looks like as below:
ViewModel--
DataTable _manualDataTable;
public DataTable ManualDataTable
{
get
{
return _manualDataTable;
}
set
{
_manualDataTable = value;
OnPropertyChanged("ManualDataTable");
}
}
For creating DataTable--
void LoadManualDataTable()
{
DataTable dtData = new DataTable();
dtData.Columns.Add("TimeStamp", typeof(DateTime));
List<DataColumn> columns = new List<DataColumn>();
var query = _dataContext.GetSenData().Where(sen => sen.LogID == ((DataLogs)SelectedItemNode).Log.LogID).Select(sen => sen.SeriesID);
var queryTS = _dataContext.GetDataSeries().Where(ts => query.Contains(ts.SeriesID));
foreach (DataSeries ts in queryTS)
{
var queryPLoc = _dataContext.GetDataLoc().Where(pLoc => pLoc.ParamID == ts.ParamID).Select(pLoc => pLoc.Name);
dtData.Columns.Add(queryPLoc.First(), typeof(string));
}
ManualDataTable = dtData;
}
XAML code--
<telerik:RadGridView Grid.Row="0" AutoGenerateColumns="True" ItemsSource="{Binding ManualDataTable}" IsReadOnly="False" CanUserDeleteRows="True" Name="radGridViewManualDataTable" ShowInsertRow="True" />
DataTable is created as expected (from LoadManualDataTable method) and
if I will add any row through the code then those rows will be binded
and will be displayed in RadGridView. But I am not able to create or delete
rows through RadGridView.
Thanks!