【问题标题】:Easy Delphi XE6 FireMonkey Controls TListBox and TStringGridEasy Delphi XE6 FireMonkey 控制 TListBox 和 TStringGrid
【发布时间】:2014-06-12 22:54:30
【问题描述】:

如何将列放入 FireMonkey TListBox,然后从 TListBox 的行的列中获取值。我正在使用这种方法:

vListRow := 'Col1Stuff' + '^I' + 'Col2Stuff';

这不是给我第一列中的 Col1Stuff 和第二列中的 Col2Stuff。

我尝试使用 TStringGrid Firemonkey 控件作为替代方法,但以下方法也不起作用:

vStringGrid.Cells[0,1] := '嗨'; vStringGrid.Cells[0,2] := '那里';

这不会在 TStringGrid 中添加任何内容。

有什么建议吗?

【问题讨论】:

    标签: delphi delphi-xe firemonkey tstringgrid tlistbox


    【解决方案1】:

    对于TListBox,使用制表符 (#9):

    ListBox1.Items.Add('Column A' + #9 + 'Column B');
    

    要取出这些值,您必须将它们解析出来,使用制表符作为分隔符(分隔符)。但是,使用 ItemIndex 通常更有效且更易读。

    由于您正在执行直接连接,您甚至可以省略“+”(但您还必须删除前导和尾随空格:

    ListBox1.Items.Add('Column A'#9'Column B');
    

    对于TStringGrid,使用项目编辑器将两个TStringColumns 添加到网格中。然后,您可以访问 Cells 属性以读取/写入值 - 请注意,Cells 由 [column, row] 值引用:

    StringGrid1.Cells[0, 1] := 'Column A';   // Column 0, Row 1
    StringGrid1.Cells[1, 1] := 'Column B';   // Column 1, Row 1
    

    【讨论】:

    • 谢谢肯。我独立地发现了 TStringGrid 的错误。我不知道 TListBox 的制表符,但我不想使用字符串操作来检索 TListBox 中列的值,因此 TStringGrid 是更好的选择。
    猜你喜欢
    • 2016-12-11
    • 1970-01-01
    • 2017-07-30
    • 1970-01-01
    • 2014-10-17
    • 2014-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多