可以让FlexGrid控件的cell具备就地编辑功能吗?

Ashura 2001-12-19 11:03:10
...全文
135 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ashura 2001-12-20
  • 打赏
  • 举报
回复
还有呢……如果record数过多需要分页怎么分?
PageSize这个例子我的MSDN里没有。
Ashura 2001-12-19
  • 打赏
  • 举报
回复
对了,用mouse点击时它好像分辨不出是否点击的是cell,又如何解决?
Ashura 2001-12-19
  • 打赏
  • 举报
回复
好说,missu@sohu.com
coolworm2000 2001-12-19
  • 打赏
  • 举报
回复
推荐一个绝好的Grid类,需要源代码请留下Email(绝对不是像炸你)
coolworm2000 2001-12-19
  • 打赏
  • 举报
回复
当然可以,在FlexGrid中放一个Edit,当产生一个EnterCell消息是把编辑框放在那里,然后编辑,当产生LeaveCell消息时把编辑框中的内容放回Cell,于是...哈哈,该给分了吧。。。。
masterz 2001-12-19
  • 打赏
  • 举报
回复
EditGrid.exe: Edit Cells in MSFlexGrid ActiveX Control (Q196833)
--------------------------------------------------------------------------------
The information in this article applies to:
The Microsoft Foundation Classes (MFC), used with:
Microsoft Visual C++, 32-bit Enterprise Edition, version 5.0
Microsoft Visual C++, 32-bit Professional Edition, version 5.0


--------------------------------------------------------------------------------


SUMMARY
The Microsoft Flex Grid Control (MSFlexGrid), which ships with Visual C++ and Visual Basic, does not support editing of individual cells.
EditGrid.exe is a sample that shows the steps needed to implement this feature in Microsoft Visual C++ using MFC.

MORE INFORMATION
The following files are available for download from the Microsoft Download Center:



EditGrid.exe
For additional information about how to download Microsoft Support files, click the article number below to view the article in the Microsoft Knowledge Base:
Q119591 How to Obtain Microsoft Support Files from Online Services
Microsoft used the most current virus detection software available on the date of posting to scan this file for viruses. Once posted, the file is housed on secure servers that prevent any unauthorized changes to the file.



NOTE: Use the -d option when running EditGrid.exe to decompress the file and recreate the proper directory structure.
Steps to Add Editing Support to MSFlexGrid
Use the Component Gallery to add the MSFlexGrid to your project. This creates MFC based wrapper classes for the control.


Use ClassWizard to create a new generic CWnd-derived class named CEditGrid. After you create this class, change it so it is derived from the MSFlexGrid class. See the REFERENCES section of this article for more information.


Use ClassWizard to create a new CEdit-derived class named CEditWnd. Handle the WM_CHAR and WM_KEYDOWN messages:


void CEditWnd::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (nChar != 13) // Ignore ENTER key.
CEdit::OnChar(nChar, nRepCnt, nFlags);
}

void CEditWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (nChar == 27) // Esc means "Cancel".
{
SetWindowText("");
ShowWindow(SW_HIDE);
GetParent()->SetFocus();
}
else if (nChar == 13) // Enter means "OK".
GetParent()->SetFocus();

CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
}
Add the following member variables to CEditGrid:


public:
CEditWnd m_edit;
long m_lBorderWidth;
long m_lBorderHeight;

int m_nLogX;
int m_nLogY;
Override the PreSubclassWindow() virtual function for CEditGrid:


void CEditGrid::PreSubclassWindow()
{
// Calculate border size.
SetRow(0);
SetCol(0);
m_lBorderWidth = GetCellLeft();
m_lBorderHeigth = GetCellTop();

// To convert grid rect from twips to DC units you need
// pixels per inch.
CDC* pDC = GetDC();
m_nLogX = pDC->GetDeviceCaps(LOGPIXELSX);
m_nLogY = pDC->GetDeviceCaps(LOGPIXELSY);
ReleaseDC(pDC);

// Create invisible edit control.
m_edit.Create(WS_CHILD|ES_MULTILINE|ES_WANTRETURN,
CRect(0,0,0,0), this, GetDlgCtrlID());
}
Handle the KeyPress, DBLClick, and LeaveCell reflected events in CEditGrid. To do this, you need to add an event map to the class:


EditGrid.h

protected:
afx_msg void OnKeyPressGrid(short FAR* KeyAscii);
afx_msg void OnDblClickGrid();
afx_msg void OnUpdateGrid();
DECLARE_EVENTSINK_MAP()

EdtGrid.cpp

BEGIN_EVENTSINK_MAP(CEditGrid, CMSFlexGrid)
// {{AFX_EVENTSINK_MAP(CEditGrid)
// }}AFX_EVENTSINK_MAP
ON_EVENT_REFLECT(CEditGrid, -603 /* KeyPress */, OnKeyPressGrid,
VTS_PI2)
ON_EVENT_REFLECT(CEditGrid, -601 /* DblClick */, OnDblClickGrid,
VTS_NONE)
ON_EVENT_REFLECT(CEditGrid, 72 /* LeaveCell */, OnUpdateGrid,
VTS_NONE)
END_EVENTSINK_MAP()

void CEditGrid::OnDblClickGrid()
{
short i = 13;
OnKeyPressGrid(&i); // Simulate a return.
}

void CEditGrid::OnKeyPressGrid(short FAR* KeyAscii)
{

ASSERT (KeyAscii != NULL);

m_edit.SetWindowText(GetText());

if (*KeyAscii == 13)
m_edit.SetSel(0,-1);
else
{
char buf[] = " ";
buf[0] = (char)*KeyAscii;
m_edit.SetSel(-1,-1);
m_edit.ReplaceSel(buf);
}

// Adjust for border height and convert from twips to screen
// units.
m_edit.MoveWindow(((GetCellLeft() - m_lBorderWidth) *
m_nLogX)/1440,
((GetCellTop() - m_lBorderHeight) * m_nLogY)/1440,
(GetCellWidth()* m_nLogX)/1440,
(GetCellHeight()* m_nLogY)/1440, FALSE);

m_edit.ShowWindow(SW_SHOW);
m_edit.SetFocus();
}

void CEditGrid::OnUpdateGrid()
{
// Check to see if edit is visible.
BOOL bVisible = ::GetWindowLong(m_edit.GetSafeHwnd(), GWL_STYLE)
& WS_VISIBLE;
if (bVisible)
{
CString cStr;
m_edit.GetWindowText(cStr);
SetText(cStr);
m_edit.SetWindowText("");
m_edit.ShowWindow(SW_HIDE);
}
}
Handle the WM_GETDLGCODE and WM_SETFOCUS messages in CEditGrid:


UINT CEditGrid::OnGetDlgCode()
{
return DLGC_WANTALLKEYS;
}

void CEditGrid::OnSetFocus(CWnd* pOldWnd)
{
CMSFlexGrid::OnSetFocus(pOldWnd);

OnUpdateGrid();
}
Create an instance of the CEditGrid control in either of the following ways:


Add the MSFlexGrid control to a dialog box or CFormView using the Resource Editor. You can then subclass the control by holding down the CTRL key and double-clicking on the control in the Resource Editor. You must edit the .h file, and change the class from CMSFlexGrid to CEditGrid.


Create the control dynamically. To do this, you need to override the CEditGrid::Create functions to call CMSFlexGrid::Create. You also need to call CEditGrid::SubClassWindow() to subclass it. For more information, see the REFERENCES section of this article.


Set the following properties for the control:
Cols = 6
Rows = 20
FillStyle = 1 - Repeat
FocusRect = 2 - Heavy



If you add the control to a dialog box or CFormView, you can use the Resource Editor. Otherwise, you need to do this programmatically after you create and subclass the control.
chenchen 2001-12-19
  • 打赏
  • 举报
回复
据我所知,也是如此。
coolworm2000 2001-12-19
  • 打赏
  • 举报
回复
不能,你需要添加一个内嵌的Edit在里面,

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧