[转帖] 如何获得单击 Crosstab DataWindow 某域的值
<table cellspacing="0" cellpadding="0" width="95%" align="center" border="0"><center><tbody><tr><td height="22"> </td><td width="100%" height="22"><div align="left"><p align="center"><b>如何获得单击 Crosstab DataWindow 某域的值</b></p></div></td><td height="22"> </td></tr><tr><td colspan="3"> </td></tr><tr><td height="560"> </td><td width="100%"><div align="left"></div><p align="left"> 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.</p><p align="left"> 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:</p><p align="left"> 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 " _ ")</p><p align="left"> 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.</p><p align="left"> 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.</p><p align="left"> Obtaining the correct column requires the use of the GetObjectAtPointer() function. This will return the column information in the form of:</p><p align="left"> columnname_columnnumber~trownumber</p><p align="left"> 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:</p><p align="left"> GetItemNumber( row, column )</p><p align="left"> The column number MUST be used since all the columns have the same name.</p><p align="left"> 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</p><blockquote><p align="left"><font color="#006443">1 string ls_detail, ls_name, ls_col<br/>2 int li_pos, li_len, li_row, li_col<br/>3 if left(getbandatpointer(),6) <> "detail" then return<br/>4 ls_detail = getobjectatpointer()<br/>5 ls_name = Object.#2.Name<br/>6 if left(ls_detail,len(ls_name)) <> ls_name then return<br/>7 li_row = row<br/>8 li_len = len(ls_detail)<br/>9 ls_col = right(ls_detail, li_len - len(ls_name))<br/>10 if left(ls_col,1) <> "_" then)<br/>11 li_col = 2<br/>12 else<br/>13 li_pos = pos(ls_col,"~t")<br/>14 li_col = integer(mid(ls_col,2,li_pos - 1) ) + 2<br/>15 end if<br/>16 parent.title = string(getitemnumber(li_row,li_col))</font></p></blockquote><p align="left"> Line 1 and 2 are variables used for the process</p><p align="left"> Line 3 - Get the band the user clicked in. if it is outside the detail area then return</p><p align="left"> Line 4 - Get the column information for the clicked item</p><p align="left"> 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</p><p align="left"> 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.</p><p align="left"> Line 7 - Get the row of the clicked item</p><p align="left"> 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.</p><p align="left"> Line 9 - get everything to the right of the column name.</p><p align="left"> 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.</p><p align="left"> Line 13 - look for the tab character ( ~t ). The column number is between the underscore and the tab character.</p><p align="left"> Line 14 - get the column number</p><p align="left"> 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.<br/>¡¡</p><p align="left"> The above code can be copied into the clicked/doubleclicked event of a DataWindow control.</p></td><td height="560"><p> </p><p> </p></td></tr><tr><td> </td><td width="100%"> </td><td> </td></tr></tbody></center></table> 看看就觉得好难啊, 哎~~~~~自己能力有限啊
页:
[1]