Hi,
I attached the following events to my grid. I am using grid grouping control. I have got a nested relationship in my grid.
private void gridGroupingControl1_TableControlCurrentCellKeyPress(object sender, GridTableControlKeyPressEventArgs e)
{
}
private void gridGroupingControl1_TableControlCellMouseDown(object sender, GridTableControlCellMouseEventArgs e)
{
}
Of these two, I am able to hit TableControlCurrentCellKeyPress but NOT TableControlCellMouseDown when i but a break point. Why is this so.
As a workaround i used
private void gridGroupingControl1_TableControlMouseDown(object sender, GridTableControlMouseEventArgs e)
{
}
I am able to hit that but the problem is that here in the event args 'e', I get th coordinated of the mouse clicked and not the row and col index of cell i clicked on. Please investigate and let me know.
HA
haneefm
Syncfusion Team
March 30, 2007 02:51 PM UTC
Hi Dinesh,
You can use the PointToRowCol method to find the RowIndex and ColIndex for a cell that is displayed at specified point. Here is a code snippet
private void gridGroupingControl1_TableControlMouseDown(object sender, GridTableControlMouseEventArgs e)
{
int row, col;
if(e.TableControl.PointToRowCol(new Point(e.Inner.X, e.Inner.Y), out row, out col))
{
Console.WrtieLine( " RowIndex =>{0} : ColIndex=>{1}",row,col);
}
}
Best regards,
Haneef
DU
dinesh upreti
March 30, 2007 04:17 PM UTC
thanks,
but the problem is that from row index and colindex, i want to access the record just as i can access e.TableControl.Table.CurrentRecord.GetData() which i can capture in cell key press event.;
so taking your approach, can i have a function to which i can pass the row index and col index to get the record back
Thanks
>Hi Dinesh,
You can use the PointToRowCol method to find the RowIndex and ColIndex for a cell that is displayed at specified point. Here is a code snippet
private void gridGroupingControl1_TableControlMouseDown(object sender, GridTableControlMouseEventArgs e)
{
int row, col;
if(e.TableControl.PointToRowCol(new Point(e.Inner.X, e.Inner.Y), out row, out col))
{
Console.WrtieLine( " RowIndex =>{0} : ColIndex=>{1}",row,col);
}
}
Best regards,
Haneef
HA
haneefm
Syncfusion Team
March 30, 2007 07:37 PM UTC
Hi Dinesh,
You can try this code snippet to get a record in a grid.
private void gridGroupingControl1_TableControlMouseDown(object sender, GridTableControlMouseEventArgs e)
{
int row, col;
if(e.TableControl.PointToRowCol(new Point(e.Inner.X, e.Inner.Y), out row, out col))
{
GridTableCellStyleInfo style = e.TableControl.Model[row, col] as GridTableCellStyleInfo;
if (style != null)
{
Element el = style.TableCellIdentity.DisplayElement;
if (el != null && el.Kind == DisplayElementKind.Record)
{
GridRecordRow recRow = el as GridRecordRow;
if (recRow != null)
{
Console.WriteLine(recRow);
}
}
}
}
Best regards,
Haneef
DU
dinesh upreti
March 31, 2007 04:32 PM UTC
Thanks, the code snippent works fine for flat data.
But a big problem still remains. As i am mentioned earlier, i am working with nested relationships.
if (el != null && el.Kind == DisplayElementKind.Record)
{
GridRecordRow recRow = el as GridRecordRow;
if (recRow != null)
{
Console.WriteLine(recRow);
}
}
In the above condition, you are checking for DisplayElementKind.Record. What if DisplayElementKind is a Nested record. In that case recRow is null while there is a child record existing.
Just to mention, the specific problem i am working upon is that when user right clicks on a particular record(s) of set of child records, a right click menu pops up, so that from there, i will pass the selected or clicked record(s) to a function which will delete that record from data source.
HA
haneefm
Syncfusion Team
April 2, 2007 03:44 PM UTC
Hi Dinesh,
Please try this code.
private void gridGroupingControl1_TableControlMouseDown(object sender, GridTableControlMouseEventArgs e)
{
Point pt = new Point(e.Inner.X, e.Inner.Y);
Element el = TableControl.PointToNestedDisplayElement(pt);
Record r = el.GetRecord(); //this will be the record in the nested table.
if ( r != null)
{
Console.WrtieLine(r);
}
}
Best regards,
Haneef