在Custom Control里数据只能显示,,,也只能显示Custom Control窗体范围的大小,
而且还不能做任何编辑动作,,,, 怎么解决这个问题?BOOL CDlg::OnInitDialog()
{
m_pGridCtrl.SubclassDlgItem((UINT)IDC_GRIDMY,this);
try
{
m_pGridCtrl.SetRowCount(4); //设置行数为k行
m_pGridCtrl.SetColumnCount(4); //k列
m_pGridCtrl.SetFixedRowCount(1); //标题行为一行
m_pGridCtrl.SetFixedColumnCount(1); //同上
}
catch (CMemoryException *e)
{
e->ReportError();
e->Delete();
return 0;
} //填充列标题
int row=0;
for(int col=0;col<4;col++)
{
GV_ITEM Item;
Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = row;
Item.col = col;
if(col==0)
{
Item.nFormat = DT_CENTER|DT_WORDBREAK;
Item.szText.Format(_T("【类别】"),col);
}
else if(col==1)
{
Item.nFormat = DT_LEFT|DT_WORDBREAK;
Item.szText.Format(_T("姓名"),col);
}
else if(col==2)
{
Item.nFormat = DT_LEFT|DT_WORDBREAK;
Item.szText.Format(_T("第二列"),col);
}
m_pGridCtrl.SetItem(&Item); } // fill rows/cols with text
for (row = 1; row < 4; row++)
for (int col = 0; col < 4; col++)
{
GV_ITEM Item;
Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = row;
Item.col = col;
if (col < 1)
{ //行标题头
Item.nFormat = DT_CENTER|DT_VCENTER |DT_SINGLELINE|DT_END_ELLIPSIS |DT_NOPREFIX;
Item.szText.Format(_T("%d"),row);
}
else if(col==1){ //第一列的值
Item.nFormat = DT_CENTER|DT_VCENTER |DT_SINGLELINE|DT_END_ELLIPSIS |DT_NOPREFIX;
string str="aa";
Item.szText.Format(_T("%s"),str);
}
else if(col==2){ //第二列第值
Item.nFormat = DT_CENTER|DT_VCENTER |DT_SINGLELINE|DT_END_ELLIPSIS |DT_NOPREFIX;
CString str;
str="bb";
Item.szText.Format(_T("%s"),str);
}
m_pGridCtrl.SetItem(&Item);
}
m_pGridCtrl.AutoSize(); //--------------设置行列距------------------
for(int a=1;a<4;a++)
m_pGridCtrl.SetRowHeight(a,21); //设置各行高
m_pGridCtrl.SetRowHeight(0,24); //设置0行高
m_pGridCtrl.SetColumnWidth(1,110); //设置2列宽
m_pGridCtrl.SetColumnWidth(2,160); //设置3列宽
m_pGridCtrl.SetColumnWidth(3,100); //设置4列宽
return true;
}
而且还不能做任何编辑动作,,,, 怎么解决这个问题?BOOL CDlg::OnInitDialog()
{
m_pGridCtrl.SubclassDlgItem((UINT)IDC_GRIDMY,this);
try
{
m_pGridCtrl.SetRowCount(4); //设置行数为k行
m_pGridCtrl.SetColumnCount(4); //k列
m_pGridCtrl.SetFixedRowCount(1); //标题行为一行
m_pGridCtrl.SetFixedColumnCount(1); //同上
}
catch (CMemoryException *e)
{
e->ReportError();
e->Delete();
return 0;
} //填充列标题
int row=0;
for(int col=0;col<4;col++)
{
GV_ITEM Item;
Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = row;
Item.col = col;
if(col==0)
{
Item.nFormat = DT_CENTER|DT_WORDBREAK;
Item.szText.Format(_T("【类别】"),col);
}
else if(col==1)
{
Item.nFormat = DT_LEFT|DT_WORDBREAK;
Item.szText.Format(_T("姓名"),col);
}
else if(col==2)
{
Item.nFormat = DT_LEFT|DT_WORDBREAK;
Item.szText.Format(_T("第二列"),col);
}
m_pGridCtrl.SetItem(&Item); } // fill rows/cols with text
for (row = 1; row < 4; row++)
for (int col = 0; col < 4; col++)
{
GV_ITEM Item;
Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = row;
Item.col = col;
if (col < 1)
{ //行标题头
Item.nFormat = DT_CENTER|DT_VCENTER |DT_SINGLELINE|DT_END_ELLIPSIS |DT_NOPREFIX;
Item.szText.Format(_T("%d"),row);
}
else if(col==1){ //第一列的值
Item.nFormat = DT_CENTER|DT_VCENTER |DT_SINGLELINE|DT_END_ELLIPSIS |DT_NOPREFIX;
string str="aa";
Item.szText.Format(_T("%s"),str);
}
else if(col==2){ //第二列第值
Item.nFormat = DT_CENTER|DT_VCENTER |DT_SINGLELINE|DT_END_ELLIPSIS |DT_NOPREFIX;
CString str;
str="bb";
Item.szText.Format(_T("%s"),str);
}
m_pGridCtrl.SetItem(&Item);
}
m_pGridCtrl.AutoSize(); //--------------设置行列距------------------
for(int a=1;a<4;a++)
m_pGridCtrl.SetRowHeight(a,21); //设置各行高
m_pGridCtrl.SetRowHeight(0,24); //设置0行高
m_pGridCtrl.SetColumnWidth(1,110); //设置2列宽
m_pGridCtrl.SetColumnWidth(2,160); //设置3列宽
m_pGridCtrl.SetColumnWidth(3,100); //设置4列宽
return true;
}
非要给你改好你的代码?
http://www.codeproject.com/KB/static/CustomControl.aspx