BoldSignEasily embed eSignatures in your .NET applications. Free sandbox with native SDK available.
how to capture the value of the cell
hi , I am new in using the SyncFusion SDK , currently I am using the trial one.
My program is like this.
Reading a files from a local folder in my Windows phone 8.1 device , and view it in a SFdatagrid while demand.
While choosing the RadioButton the view will popup and be filled with the data from the chosen test file.
Check the code I am using below
private async void RCustFile_Checked(object sender, RoutedEventArgs e)
{
this.theGrid.Visibility = Visibility.Visible;
theGrid.Columns.Add(new GridTextColumn() { HeaderText = "Cust#", MappingName = "[" + (0) + "]" });
theGrid.Columns.Add(new GridTextColumn() { HeaderText = "Cust Name", MappingName = "[" + (1) + "]" });
List<List<string>> rows = new List<List<string>>();
// Get the local folder.
StorageFolder local = KnownFolders.DocumentsLibrary;
if (local != null)
{
// Get the file.
var file = await local.OpenStreamForReadAsync("CUSTD01.DOT");
//read all the lines
string delimiter = ",";
StreamReader streamReader = new StreamReader(file);
string allData = streamReader.ReadToEnd();
string[] frows = allData.Split("\r".ToCharArray());
// data
foreach (string y in frows)
{
var t = new List<string>();
string[] items = y.Split(delimiter.ToCharArray());
for (int i = 0; i < 2; i++)//how many columns in the grid
{
t.Add(items[i]);
}
rows.Add(t);
}
theGrid.ItemsSource = rows;
}
}
From the code above I am trying to get all the information I need to carry on with my program
Which is the value of the cells i am chosen by tapping on the cell OR to get the data of the line row.
I tried a lot but nothing working. Please help.
void sfGrid_Loaded(object sender, RoutedEventArgs e) { var rowGenerator = this.sfGrid.GetRowGenerator(); var items = rowGenerator.Items; var rowData = (items[1].RowData); var row = (rowData as Employees); |
Hi Nedal,
Please ignore the previous update. Please find the update below,
You can get the cell information while tabbing the cell by handling SfDataGrid.CurrentCellActivating event as in the below code snippet,
this.sfgrid.CurrentCellActivating += sfgrid_CurrentCellActivating;
void sfgrid_CurrentCellActivating(object sender, CurrentCellActivatingEventArgs args)
{
if (args.ActivationTrigger == ActivationTrigger.Mouse || args.ActivationTrigger == ActivationTrigger.Touch)
{
var record = sfgrid.GetRecordAtRowIndex(args.CurrentRowColumnIndex.RowIndex);
if (record == null)
return;
var data = record as SalesByYear;
var colindex = sfgrid.ResolveToGridVisibleColumnIndex(args.CurrentRowColumnIndex.ColumnIndex);
if (colindex >= 0)
{
var column = sfgrid.Columns[colindex];
}
//You can set args.Cancel as true if you don't want selection in Grid
args.Cancel = true;
}
}
Note: we have set SelectionMode as one. If you don’t want selection, then you can cancel the selection in CurrentCellActivating event by setting args.Cancel = true as.
Sample:
http://www.syncfusion.com/downloads/support/directtrac/137596/WPSample-1865118023.zip
Please let us know if you need any further assistance on this.
Thanks,
Sivakumar
Private void theGrid_CurrentCellActivating(object sender, CurrentCellActivatingEventArgs args)
{
if (args.ActivationTrigger == ActivationTrigger.Mouse || args.ActivationTrigger == ActivationTrigger.Touch)
{
var record = theGrid.GetRecordAtRowIndex(args.CurrentRowColumnIndex.RowIndex);
if (record == null)
return;
//var data = record as SalesByYear;
var colindex = theGrid.ResolveToGridVisibleColumnIndex(args.CurrentRowColumnIndex.ColumnIndex);
if (colindex >= 0)
{
var column = theGrid.Columns[colindex];
ItemText.Text = column.ToString();
}
//You can set args.Cancel as true if you don't want selection in Grid
//args.Cancel = true;
}
}
the result is "Syncfusion.UI.Xaml.Grid.GridtTextColumn"
and I have checked the sample you gave , it's seems it's for WP platform not WP8
unless it doesn't make any difference.
do I have to activate anything to avoid this result
Hi
Nedal,
Thank you
for your update.
You can get
the cellvalue from datagrid using GetRecordAtRowIndex in SelectionChanging Event
as shown in the following code example :
Code
Snippet:
this.sfgrid.SelectionChanging
+= sfGrid_SelectionChanging;
void
sfGrid_SelectionChanging(object
sender, GridSelectionChangingEventArgs
e)
{
var
record = sfgrid.GetRecordAtRowIndex(sfgrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.RowIndex);
if
(record == null)
return;
var
data = record as
SalesByYear;
//you
can get the cell value from data var
Name = data.Name; //for
example get the Name property from data variable at the specified
index
} |
We have
prepared a sample in WP8 platform and please find the sample from the following
location:
Sample
Link: PhoneApp3.zip
Kindly let
us know if you require any further assistance.
Regards,
Jayapradha
Hi
Nedal,
Please
ignore our previous update.
You
can get the cellvalue from SelectionChanging Event using
GetPropertyAccessProvider() as shown in the below code snippet.
Code Snippet:
void
sfGrid_SelectionChanging(object sender, GridSelectionChangingEventArgs e)
{
var
record = sfgrid.GetRecordAtRowIndex(sfgrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.RowIndex);
if
(record == null)
return;
var colIndex
=
sfgrid.ResolveToGridVisibleColumnIndex(sfgrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.ColumnIndex);
if
(colIndex >= 0)
{
var
column = sfgrid.Columns[colIndex];
var
cellValue = sfgrid.View.GetPropertyAccessProvider().GetValue(record,
column.MappingName);
}
} |
Please
find the modified sample from the below location,
Sample Link: PhoneApp3.zip
Please
refer the below KB document to get the cell value: http://www.syncfusion.com/kb/3011/how-to-get-information-from-the-selected-cells-when-using-cell-selection
Kindly
let us know if you require any further assistance on this.
Regards,
Jayapradha
void datagrid_SelectionChanging(object sender, GridSelectionChangingEventArgs e) { var record = datagrid.GetRecordAtRowIndex(datagrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.RowIndex); if (record == null) return; var recordItems = record as List<string>; var colIndex = datagrid.ResolveToGridVisibleColumnIndex(datagrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.ColumnIndex); if (colIndex >= 0) { var cellValue = recordItems[colIndex]; Console.WriteLine(cellValue); //var column = datagrid.Columns[colIndex]; //var cellValue = datagrid.View.GetPropertyAccessProvider().GetValue(record, column.MappingName); }
|
Hi Nedal,
Thank you for your update.
We have analyzed your requirement with sample provided by you. In that sample, the selected record is type of List<string> and so you can get the cellvalue based on the selected index as shown in the below code snippet,
Code Snippet:
void datagrid_SelectionChanging(object sender, GridSelectionChangingEventArgs e) { var record = datagrid.GetRecordAtRowIndex(datagrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.RowIndex); if (record == null) return; var recordItems = record as List<string>; var colIndex = datagrid.ResolveToGridVisibleColumnIndex(datagrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.ColumnIndex); if (colIndex >= 0) { var cellValue = recordItems[colIndex]; Console.WriteLine(cellValue); //var column = datagrid.Columns[colIndex]; //var cellValue = datagrid.View.GetPropertyAccessProvider().GetValue(record, column.MappingName); }
|
Hi Nedal,
Thank you for your update.
Please let us know if you have any other queries.
Regards,
Jayapradha