请各位大侠指点,在listBox和grid的使用中,怎么判断他们当中是否有被选中的行?

解决方案 »

  1.   

    //ListBox:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
        if ListBox1.ItemIndex > -1 then
          ShowMessage('有选中的!')
    end;//Grid是那种Grid??
      

  2.   

    这是listBox的
    有一个SelCount,下面有说明
    Indicates the number of items that are selected when multiple selections are allowed.Delphi syntax:property SelCount: Integer;C++ syntax:__property int SelCount = {read=GetSelCount, nodefault};Description SelCount is read-only. Use SelCount to find the number of selected items in the list box when the MultiSelect property is true.When the MultiSelect property is false, SelCount is always ?.
      

  3.   

    sorry,上面的是多选才有效,单选的话,二楼说的对!
      

  4.   

    grid是我们公司自己继承delphi中的DBGrid制作的
      

  5.   

    DBGrid获得焦点后,默认第一行是选中的
      

  6.   

    if DBGrid1.SelectedRows.Count > 0 then
        ShowMessage('有选中的行!');
      

  7.   

    受用,我最近在使用ListBox做例子,让自己加深对于这方面的理解。
      

  8.   

    TListBox:
    ItemIndexTStringGrid:
    Row
      

  9.   

    1:if ListBox1.ItemIndex > -1 then
          ShowMessage('有选中的!')
    2.if DBGrid1.SelectedRows.Count > -1 then
        ShowMessage('有选中的行!');
      

  10.   

    if listbox1.selected[i] then
       ShowMessage('selected');