10-17-2012 05:06 PM
Hello,
Can anyone please help me understand how to access values in neighboring cells in the XTable EventValSet event?
Sub XTable1_EventValSet(ByRef This, Row, Col, ByRef Cell) 'Created Event Handler Select Case Col Case 1 neighbor2 = This.Columns(2).Cell.Text 'note this is pseudo code...how do you properly address an adjacent cell? Case 2 neighbor1 = This.Columns(1).Cell.Text End Select End Sub
This code is for discussion purposes...I couldn't find a way to do it.
thanks,
Jim
Solved! Go to Solution.
10-18-2012 03:39 PM
Jim,
Thanks for posting this. I've been looking into this for an answer, but have yet to come up with a direct way to reference the value using the XTable interface. I'm still looking into this, but it does not appear there is a very direct way of doing this.
Alternatively, since in an XTable you tell it where to get the data, you could always use the Row and Column indices returned from EventValSet to index the original data source, particularly it's neighbor (row +- 1).
An additional method would be to use a Table (if you do not have a specific reason why you need to use an XTable). The Table object has a Cells(row, col) property that you can use to get neighboring values (row +- 1).
10-19-2012 08:07 AM
Kevin,
I contacted R&D about this question, and they offered some very useful answers.
The first thing we have to understand is that the XTable does not store any values. This allows XTables to have very high performance, even for large datasets. Because of this, there is no built in way to access neighboring (or arbitrary) cell values. We are limited to what we receive in the event handlers since the XTable is an event-based structure.
Alternatively, we can write our own class that implements the XTable interface. In this manner, we have the ability to reuse the EventValGet Handler in the EventValSet Handler to access arbitrary cell values. Our new class must implement all cell properties which are accessed in the EventValGet code, but there are not too many, so this would not be unreasonable. An example is provided here:
class MyNewCell Public Text end class Sub XTable1_EventValSet(ByRef This, Row, Col, ByRef Cell) Dim oCell Set oCell = new MyNewCell Dim neighbor Select Case Col Case 1 call XTable1_EventValGet(This, Row, Col + 1, oCell, false) neighbor = oCell.Text 'note this is pseudo code... get adjacent cell in line above Case 2 call XTable1_EventValGet(This, Row, Col - 1, oCell, false) neighbor = oCell.Text End Select msgbox neighbor End Sub Sub XTable1_EventValGet(ByRef This, Row, Col, ByRef Cell, IsInputCell) 'Erzeugter Event-Handler Cell.Text = Row & "-" & Col End Sub
It should be noted that while this is a workaround, it goes against the XTable design rules.