CDataGrid部分函数功能说明:
GetRowHeight()得到行高
GetRow得到光标所在行的行号(看来,上面的计算是多余的了,直接调用它就可以得到鼠标点击的行号了)
GetCol得到光标所在列的列号
GetVisibleRows得到当前窗口显示的行数
GetFirstRow得到当前窗口第一行的绝对行号
.......
找到了,就是它!
以下是实现代码:
try
{
int iRow=m_datagrid.GetRow();
if (iRow<0)//点击的是列头
{
return;
}
int iCol=m_datagrid.GetCol();
if (iCol>=0)//点击的不是行头
{
return;
}
VARIANT IndexRow=m_datagrid.GetFirstRow();
IndexRow.lVal+=iRow;
VARIANT IndexCol;
IndexCol.vt = VT_I4;
IndexCol.lVal = 0; //取第一列
CString str=m_datagrid.GetColumns().GetItem(IndexCol).GetText();
MessageBox(str);
}
catch(...)
{
}
在加上头文件#include "column.h"
#include "columns.h"