A crosstab DataWindow is a unique type of DataWindow. When it is built in the DataWindow painter, it is comprised of one row and one column. The remaining columns are dynamically created at runtime. This prevents the use of many of the functions normally used to obtain the value of a clicked item. At runtime, all columns have the same name as the column that was created in the DataWindow painter. The distinguishing difference in the column name is the suffix assigned to the column name. The column names take the form of: columnname_columnnumber~trownumber (row and column numbers are separated by a tab character and the column number is separated from the column name by an underscore character " _ ") The column number is relative to original column that was built with the DataWindow. The original column does not have a column number using the above notation. As an example a column number of two (2) would indicate that the column is the second column to the right of the original column. If you need the value of any of the detail columns they can not be obtained since the column name is the same and the column number must be parsed from a string. The only argument that can be used is the row argument of the clicked event. This will correctly return the row of the detail item clicked. Obtaining the correct column requires the use of the GetObjectAtPointer() function. This will return the column information in the form of: columnname_columnnumber~trownumber The column number has to be parsed from this value and used with the row number to obtain the data for the clicked item. With the row/column combination, we can use a GetItemNumber (or whatever GetItem is needed) in the form of: GetItemNumber( row, column ) The column number MUST be used since all the columns have the same name. Below is the example code used to obtain the value of a clicked item in a crosstab DataWindow. Each line of code has a number and will be explained using these numbers as reference 1 string ls_detail, ls_name, ls_col 2 int li_pos, li_len, li_row, li_col 3 if left(getbandatpointer(),6) <> "detail" then return 4 ls_detail = getobjectatpointer() 5 ls_name = Object.#2.Name 6 if left(ls_detail,len(ls_name)) <> ls_name then return 7 li_row = row 8 li_len = len(ls_detail) 9 ls_col = right(ls_detail, li_len - len(ls_name)) 10 if left(ls_col,1) <> "_" then) 11 li_col = 2 12 else 13 li_pos = pos(ls_col,"~t") 14 li_col = integer(mid(ls_col,2,li_pos - 1) ) + 2 15 end if 16 parent.title = string(getitemnumber(li_row,li_col))
Line 1 and 2 are variables used for the process Line 3 - Get the band the user clicked in. if it is outside the detail area then return Line 4 - Get the column information for the clicked item Line 5 - Get the name of the column from the column number. We have to use column #2 in a crosstab since column number 1 is not in the detail area we need Line 6 - compare the column name from the column information from line 4 with the column name of the columns in the detail area we need. If they do not match, that means the user clicked in column 1, which is outside the detail area we need. This is needed since the GetBandAtPointer() will still return "detail" for any clicks in column one. Line 7 - Get the row of the clicked item Line 8 - Get the length of the column detail information obtained in line 4. This will be needed for parsing the column number from the detail information. Line 9 - get everything to the right of the column name. Line 10 and 11 - check for an "_" underscore. If there is not one, then we are in the first column of the detail area, which is really column 2. Line 13 - look for the tab character ( ~t ). The column number is between the underscore and the tab character. Line 14 - get the column number Line 16 - this is to display the value of the clicked item in the title bar of the window. (for demo purposes only). You will use the return from the GetItem for your value. ¡¡ The above code can be copied into the clicked/doubleclicked event of a DataWindow control. |