We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Get underlying data by mouse event in GGC

Hello,

I wish get underlying data in Gridgroupingcontrol by this code:

Sub gc_TableControlMouseDown()
Dim pt As Point = New Point(e.Inner.Location.X, e.Inner.Location.Y)
Dim gtc As GridGroupingControl = sender
Dim el As Element = gtc.PointToNestedDisplayElement(pt)
Dim ParentName As String = el.ParentTableDescriptor.Name
Dim cm As CurrencyManager = ggBusiness.GetTable(ParentName).GetCurrencyManager
Dim dv As DataView = cm.List
...
End Sub

The problem is that: PointToNestedDisplayElement is not member of GridGroupingControl.
Please advise me how to work around this?

Thanks,
Harry


4 Replies

AD Administrator Syncfusion Team March 17, 2008 08:09 AM UTC

Hi Harry,

Thank you for using Syncfusion products.

You can get the underlying DataRow when you call r.GetData(). That will return the DataRowView element for the record. You can get at the currentcell using gridGroupingControl1.TableControl.CurrentCell. You can refer the below forum thread for more details.

Here is the forum thread link:

'>http://www.syncfusion.com/support/forums/message.aspx?MessageID=13296">
http://www.syncfusion.com/support/forums/message.aspx?MessageID=13296

Please let me know if you have any questions.

Regards,
Subhasheela R





HA Harry March 17, 2008 11:27 AM UTC

Dear Subhasheela:

1. I tried to translate the code from C to VB but got error.
Dim el As Element = ggc.TableControl.Table.CurrentElement
Dim rec As Record = Nothing
Dim TableName As String = vbNullString
Dim drv As DataRowView = Nothing
Dim col As Integer = 0
Dim field As Integer = 0
Dim o As Object = Nothing
If Not IsNothing(el) Then
If el.Kind = DisplayElementKind.Record Then
rec = el.GetRecord
drv = CType(el.GetData, DataRowView)
TableName = el.ParentTableDescriptor.Name
col = ggc.TableControl.CurrentCell.ColIndex
field = ggc.TableDescriptor.ColIndexToField(col)
o = rec.GetValue(ggc.TableDescriptor.Fields(field))
ElseIf el.Kind = DisplayElementKind.NestedTable Then

Dim gnt As GridNestedTable = el
Dim gnt1 As GridNestedTable = gnt
While Not IsNothing(gnt1) AndAlso Not IsNothing(gnt1.ChildTable)
gnt = gnt1
gnt1 = gnt.ChildTable.ParentTable.CurrentElement
End While
rec = gnt.ChildTable.ParentTable.CurrentRecord
drv = CType(gnt.GetData, DataRowView)

TableName = gnt.ChildTable.ParentTable.TableDescriptor.Name
Dim tableControl As GridTableControl = ggc.GetTableControl(TableName)
col = tableControl.CurrentCell.ColIndex
field = gnt.ChildTable.ParentTable.TableDescriptor.ColIndexToField(col)
o = rec.GetValue(gnt.ChildTable.ParentTable.TableDescriptor.Fields(field))
End If
...
End Sub

Error on:
gnt1 = gnt.ChildTable.ParentTable.CurrentElement --> invalidcastexception: Unable to cast object type GridRecordWithValueCache to type GridNestedTable

Kindly advise, how to fix it?
Since there are some visible columns removed in the table, the column index was incorrect.

2. I tried to column info by mouse down event, but this code only work on parent table, it didn't work on nested tables:
Dim pt As Point = New Point(e.Inner.Location.X, e.Inner.Location.Y)
Dim el As Element = ggBusiness.TableControl.PointToNestedDisplayElement(pt)
Dim row As Integer
Dim col As Integer
ggBusiness.TableControl.PointToRowCol(pt, row, col, -1)
Dim Column As GridColumnDescriptor = e.TableControl.Table.GetColumnDescriptorAt(row, col)

'Column' value is 'Nothing' at nested table, how to work it out correctly?

Best Regards,
Harry



AD Administrator Syncfusion Team March 27, 2008 10:54 AM UTC

Hi Harry,

Extremely sorry for the long delay in getting back to you.

With the nested tables, you need to get the child table you want, for getting the selected rows. Here is a code snippet:


Dim table As Syncfusion.Windows.Forms.Grid.Grouping.GridTable = Me.GridGroupingControl1.Table
Console.WriteLine("The " & table.TableDescriptor.Name & " selected records")
printSelectedRecords(table)
For Each rt As Syncfusion.Grouping.Table In table.RelatedTables
Console.WriteLine("The " & rt.TableDescriptor.Name & " selected records")
printSelectedRecords(TryCast(rt, Syncfusion.Windows.Forms.Grid.Grouping.GridTable))
Next rt


Kindly have a look into the sample available in the link below and please let me know if it helps:


http://websamples.syncfusion.com//samples/Grid.Windows/F72369/main.htm


Regards,
Subhasheela R




HA Harry April 9, 2008 06:20 AM UTC

Dear Subhasheela:

Thanks, it's perfect.
Harry



Loader.
Live Chat Icon For mobile
Up arrow icon