Think from getting the DBGRID line number

zhaozj2021-02-11  185

Get DBGRID currently selected line numbers and columns?

This is a function of many people often need to implement, but the TDBGRID class does not provide properties similar to col and row, so they cannot be obtained directly. So many friends began to start thinking from DataSource. But we calm down, although TDBGRID did not provide a COL and ROW attribute, his base class TCUSTOMGRID is a ROW and COL attributes. So we can repart by a class called TMGRID to output the Row and COL attributes, and convert DBGRID instances into TMGRID, which can accurately obtain these two attributes, the code is as follows:

Type

TMGRID = Class (TDBGRID);

...

Begin

...

ShowMessage (INTTOSTR (TMGIRD (DBGRID1) .ROW);

ShowMessage (INTTOSTR (TMGIRD (DBGRID1 ).ROL);

...

END;

From this example, we are not difficult to get this revelation. When we can't get directly from the currently used class, don't rush to seek to seek, we can go to examine its base class (base class " Class ..., have been looking for), whether to provide us with the information we need. If so, we can simply inherit a new class from the current class (of course you can also inherit from its base class, such as the above example, TMGrids can even inherit from the TCUSTOMGRID class. But for security, I suggest Inherited directly from the current class), then force the current object as a new type, then we can easily get the information we need.

转载请注明原文地址:https://www.9cbs.com/read-5743.html

New Post(0)