简体   繁体   English

在MFC中编辑列表控件数据(编辑行,复制和粘贴)

[英]Edit List control data in MFC (edit lines, copy & paste)

I have a list control with some data, and i need to be able to edit column (i have few columns but only one of them should be editable), also i need to be able in some way to copy multiple rows from this column and also put data (paste) from clipboard. 我有一个包含一些数据的列表控件,我需要能够编辑列(我只有很少的列,但是其中只有一个是可编辑的),我还需要能够以某种方式从该列复制多行并还可以从剪贴板放入数据(粘贴)。 Is this possible to enable that features with minimum efforts? 是否可以以最小的努力启用这些功能? Thank you. 谢谢。

Update: I found solution for editing filed, but it works strange. 更新:我找到了编辑字段的解决方案,但是效果很奇怪。 Here's the article http://www.codeproject.com/Articles/1124/Editing-Sub-Items-in-List-Control 这是文章http://www.codeproject.com/Articles/1124/Editing-Sub-Items-in-List-Control

With authors example it works pretty good, but when i tried to remake it for my tabbed project i got an incorrect display of editbox, it's related to tabbed dialog coordinates but i still can't figure out how to fix it. 以作者为例,它工作得很好,但是当我尝试为选项卡式项目重新制作它时,显示的编辑框显示不正确,这与选项卡式对话框的坐标有关,但是我仍然不知道如何解决它。

在此处输入图片说明

The article you reference has some problems. 您引用的文章有一些问题。 If you take a look at the discussions posts after the article, you'll notice some comments indicating a problem with the placement of the CEdit control. 如果您看一下文章后的讨论帖子,您会注意到一些注释,表明CEdit控件的位置存在问题。 In particular, look for "CEdit placement error". 特别是,查找“ CEdit放置错误”。 More importantly, if you take a look at the code that was posted, you'll see hard coded adjustments to the SetWindowPos command. 更重要的是,如果您查看发布的代码,则会看到对SetWindowPos命令的硬编码调整。 It's never a good idea to hard code adjustments. 硬代码调整绝不是一个好主意。 They should always be calculated dynamically if possible. 如果可能,应始终动态地计算它们。

I have succeeded in fixing the positioning problems by adding one line of code and removing the hard coded adjustments. 我通过添加一行代码并删除了硬编码调整项,成功解决了定位问题。 See my code below. 请参阅下面的代码。

RECT rect1, rect2;
// this macro is used to retrieve the Rectanle 
// of the selected SubItem
ListView_GetSubItemRect(hWnd1, temp->iItem,
    temp->iSubItem, LVIR_BOUNDS, &rect);
::MapWindowPoints(hWnd1, m_hWnd, reinterpret_cast<LPPOINT>(&rect), 2);

//Get the Rectange of the listControl
::GetWindowRect(temp->hdr.hwndFrom, &rect1);
//Get the Rectange of the Dialog
::GetWindowRect(m_hWnd, &rect2);    

int x = rect1.left - rect2.left;
int y = rect1.top - rect2.top;

if (nItem != -1)
    ::SetWindowPos(::GetDlgItem(m_hWnd, IDC_EDIT1),
    HWND_TOP, rect.left, rect.top,
    rect.right - rect.left,
    rect.bottom - rect.top, NULL);

::ShowWindow(::GetDlgItem(m_hWnd, IDC_EDIT1), SW_SHOW);
::SetFocus(::GetDlgItem(m_hWnd, IDC_EDIT1));
//Draw a Rectangle around the SubItem
//::Rectangle(::GetDC(temp->hdr.hwndFrom),
//  rect.left, rect.top, rect.right, rect.bottom);
//Set the listItem text in the EditBox
::SetWindowText(::GetDlgItem(m_hWnd, IDC_EDIT1), str);

The line I added is for the MapWindowPoints to convert the coordinates of the list control item to the coordinate space of the dialog. 我添加的行用于MapWindowPoints,以将列表控件项的坐标转换为对话框的坐标空间。 I've also commented out drawing the rectangle around the edit box since it doesn't seem to add any value. 我也注释掉了在编辑框周围绘制矩形,因为它似乎没有添加任何值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM