我要在ListView里面点击某个格子时候,显示一个ComboBox进行选择,请教各路高手

smxn 2003-10-17 10:13:04
我要在ListView里面点击某个格子时候,显示一个ComboBox进行选择,请教各路高手
...全文
58 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
ccrun.com 2003-12-15
  • 打赏
  • 举报
回复
怎么全是up的。楼主呢,也不吭一声。
liuliuisme 2003-12-15
  • 打赏
  • 举报
回复
up
「已注销」 2003-12-15
  • 打赏
  • 举报
回复
关注
  • 打赏
  • 举报
回复
up
  • 打赏
  • 举报
回复
up
ccrun.com 2003-12-12
  • 打赏
  • 举报
回复
仿季大侠的代码给你写了一份:

在Form上添加一个ListView和一个ComboBox,并适当添加些数据。

// .h file
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TListView *ListView1;
TComboBox *ComboBox1;
void __fastcall ListView1DblClick(TObject *Sender);
void __fastcall ComboBox1Exit(TObject *Sender);
private: // User declarations
int nCol;
TListItem *Item;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif


// .cpp file
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
ListView1->RowSelect = true;
ListView1->ViewStyle = vsReport;
ComboBox1->Visible = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListView1DblClick(TObject *Sender)
{
int nWidth, nHeight;
int nX, nY;
int nCount;
TRect Rect;
TPoint Pos;

Pos = ListView1->ScreenToClient(Mouse->CursorPos);
Item = ListView1->GetItemAt(Pos.x, Pos.y);
if (Item==NULL)
//没有点在Item上
return;
nCount = ListView1->Columns->Count;
nX = -GetScrollPos(ListView1->Handle, SB_HORZ);
for(nCol=0; nCol<nCount; nX+=nWidth, nCol++)
{
nWidth = ListView_GetColumnWidth(ListView1->Handle, nCol);
if (Pos.x <= nX + nWidth)
break;
}
if (nCol == nCount)
return;
if (nX < 0)
{
nWidth += nX;
nX = 0;
}

ComboBox1->Visible = true;
ActiveControl = ComboBox1;
Rect = Item->DisplayRect(drBounds);
Pos.x = nX;
Pos.y = Rect.Top;
MapWindowPoints(ListView1->Handle, Handle, (POINT*)&Pos, 1);
ComboBox1->SetBounds(Pos.x, Pos.y-1, nWidth, Rect.Height()+2);
ComboBox1->Text = nCol==0 ? Item->Caption : Item->SubItems->Strings[nCol-1];

}
//---------------------------------------------------------------------------
void __fastcall TForm1::ComboBox1Exit(TObject *Sender)
{
ComboBox1->Visible = false;
if (nCol == 0)
Item->Caption = ComboBox1->Text;
else
{
while(Item->SubItems->Count < nCol)
Item->SubItems->Add("");
Item->SubItems->Strings[nCol-1] = ComboBox1->Text;
}
}
//---------------------------------------------------------------------------
chifengwatch 2003-12-12
  • 打赏
  • 举报
回复
搜索一下
tg1965 2003-10-17
  • 打赏
  • 举报
回复
几年前做过一个,代码忘记了,大概是在那个格子里NEW一个ComboBox.然后初始化那个ComboBox
就可以了.
我不懂电脑 2003-10-17
  • 打赏
  • 举报
回复
搜索一下吧,老问题了。
iris_zhu 2003-10-17
  • 打赏
  • 举报
回复
常听大家说自己画一个,怎么画呀?我也想知道!能不能举个例子呀!
smxn 2003-10-17
  • 打赏
  • 举报
回复
请教各路大侠!

604

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder VCL组件使用和开发
社区管理员
  • VCL组件使用和开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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