【问题标题】:Firemonkey: How do I use a TComboBox in a TStringGrid to make it work from the keyboard?Firemonkey:如何在 TStringGrid 中使用 TComboBox 使其通过键盘工作?
【发布时间】:2023-01-27 23:39:18
【问题描述】:

当从键盘使用时,TStringGrid 中的 TComboBox 不起作用。它不会更新单元格值。

我希望它在我使用鼠标时可以通过键盘工作。我应该如何更改代码以使其在键盘上工作?还是死案?

谢谢米卡

void __fastcall TForm1::ChangeStringGridComboBox(TObject* Sender)
{
    TComboBox* combobox = dynamic_cast<TComboBox*>(Sender);
    if (combobox && combobox->ItemIndex > -1) {
        StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row] =
            combobox->Items->Strings[combobox->ItemIndex];
    }
}

//---------------------------------------------------------------------------

void __fastcall TForm1::StringGrid1CreateCustomEditor(
    TObject* Sender, TColumn* const Column, TStyledControl*&Control)
{
    TComboBox* combobox = new TComboBox(this);

    if (Column == Column1) {
        Control = combobox;
        combobox->Items->Assign(Memo1->Lines);
        combobox->ItemIndex = combobox->Items->IndexOf(
            StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row]);

        if (combobox->ItemIndex > -1) {
            StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row] =
                combobox->Items->Strings[combobox->ItemIndex];
        }
        combobox->OnChange = &ChangeStringGridComboBox;
    }
}

【问题讨论】:

    标签: c++builder


    【解决方案1】:

    要在 TStringGrid 中使用 TComboBox 并使其通过键盘工作,您可以按照以下步骤操作:

    1.) 在您的窗体上放置一个 TComboBox 组件并将其 Parent 属性设置为 TStringGrid。

    2.)Read More

    【讨论】:

      猜你喜欢
      • 2014-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多