如何实现这样的下拉列表?

踏岸寻柳 2003-10-15 11:21:20
想做一个名称、类型对应并都可选(下拉列表)的表格状的东西,希望利用现成的组件来实现。(两列,都是下拉列表的形式)
ValueListEditor组件的第二个列能够做成下拉列表的形式,但是第一个列似乎是固定的。
StringGrid组件的Cell是否能够做成下拉列表的形式呢!?
...全文
48 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
swites 2003-10-15
  • 打赏
  • 举报
回复
up!
qiuafa 2003-10-15
  • 打赏
  • 举报
回复
捧场!
domustdo 2003-10-15
  • 打赏
  • 举报
回复
在StringGrid的cell中嵌入ComboBox
void __fastcall TForm1::FormCreate(TObject *Sender)
{
...
pComboEditor = new TComboBox(this);
pComboEditor->Parent = this;
pComboEditor->Visible = false;
pComboEditor->Style = csDropDownList;
pComboEditor->OnChange = ComboEditorChange;
...
}

void __fastcall TForm1::PlaceComboEditor(void)
{
TRect Rect = StringGrid1->CellRect(StringGrid1->Col,StringGrid1->Row);
pComboEditor->Top = StringGrid1->Top;
pComboEditor->Left = StringGrid1->Left;
pComboEditor->Text = EmptyStr;
pComboEditor->Top = pComboEditor->Top + Rect.Top +
StringGrid1->GridLineWidth;
pComboEditor->Left = pComboEditor->Left +
Rect.Left + StringGrid1->GridLineWidth+1;
pComboEditor->Height = (Rect.Bottom - Rect.Top) + 1;
pComboEditor->Width = (Rect.Right - Rect.Left) + 0;
pComboEditor->Visible = true;
pComboEditor->SetFocus();
}
fatwave 2003-10-15
  • 打赏
  • 举报
回复
class cTest : public TObject
{
public:
int iID;//商品ID
AnsiString sName;//商品名称
};

for(int i=0; i<10; i++)
{
test = new cTest;
test->iID = i+100;
test->sName = AnsiString(i);
ComboBox1->Items->AddObject(test->sName,test);
//delete test;
}

ComboBox1->ItemIndex = 5;
int j = ((cTest*)(ComboBox1->Items->Objects[4]))->iID;
ShowMessage(AnsiString(j));
在ComboBox1中加入一个对象
改一改应该可以实现你的要求!!
踏岸寻柳 2003-10-15
  • 打赏
  • 举报
回复
明白!
多谢!
结帖!
domustdo 2003-10-15
  • 打赏
  • 举报
回复
嗯,或者是放在OnSelectCell事件处理方法里,注意上面要把这一句修改一下:
TRect Rect = StringGrid1->CellRect(StringGrid1->Col,StringGrid1->Row);
里面的Col和Row为当前选中的cell,如果是在特定cell显示,这两个值要修改成特定cell的index值
踏岸寻柳 2003-10-15
  • 打赏
  • 举报
回复
哦,是不是可以在StringGrid的Cell成为焦点时就用PlaceComboEditor
踏岸寻柳 2003-10-15
  • 打赏
  • 举报
回复
1. 动态生成组件,设置属性、方法;
2. 函数PlaceComboEditor是用在哪里的?(不太明白)
domustdo 2003-10-15
  • 打赏
  • 举报
回复
void __fastcall TForm1::ComboEditorChange(TObject *Sender)
{
StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row] =
pComboEditor->Items->Strings[pComboEditor->ItemIndex];
}

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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