Skip to content

Instantly share code, notes, and snippets.

@srafay
Created June 10, 2022 03:07
Show Gist options
  • Save srafay/106b91e4c9211fec222956ac344e12c7 to your computer and use it in GitHub Desktop.
Save srafay/106b91e4c9211fec222956ac344e12c7 to your computer and use it in GitHub Desktop.
Get SFGrid Ref from CellSelectedHandler Event (Syncfusion Blazor C#)
void CellSelectedHandler<T>(CellSelectEventArgs<T> args, SfGrid<T> grid)
{
if (args.IsCtrlPressed)
{
System.Reflection.FieldInfo grid = args.GetType().GetField("Parent", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.GetField | BindingFlags.Public);
var col = grid.FieldType.GetProperty("Columns");
var wrapped = ObjectAccessor.Create(col);
var argsFM = ObjectAccessor.Create(args);
var gridFM = ObjectAccessor.Create(grid);
Type gridType = typeof(T);
var xx = grid.GetType().GetMember("Columns", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.GetField);
var x = grid.FieldType.GetMethod("get_Columns");
dynamic dArgs = args;
dynamic dParent = dArgs.Parent;
var argsParent = args.GetType().GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Single(x => x.Name == "Parent");
var argsProps = args.GetType().GetProperties(BindingFlags.Public | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).OrderBy(pi => pi.Name).ToList();
var argsFields = args.GetType().GetFields(BindingFlags.Public | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).OrderBy(pi => pi.Name).ToList();
var tParent = typeof(T).GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
var tProps = typeof(T).GetType().GetProperties(BindingFlags.Public | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).OrderBy(pi => pi.Name).ToList();
var tFields = typeof(T).GetType().GetFields(BindingFlags.Public | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).OrderBy(pi => pi.Name).ToList();
object ParentValue = Parent.GetValue(args, null);
}
}
@srafay
Copy link
Author

srafay commented Jun 10, 2022

To add event in SfGrid

<GridEvents CellSelected="args => CellSelectedHandler(args, ContractsPartiesGrid)" TValue="User"></GridEvents>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment