如何知道用户在 DBGrid 中选择了某行?
How to know that user selected some row in DBGrid?
我在 DBGrid 之外有 DBGrid 和按钮 "Delete"。我如何确定用户在 DBGrid 中选择了某个字符串?因为如果打开表单并且没有在 DBGrid 中选择字符串,并且用户单击了按钮 "Delete" - 我需要向他显示警告框 "No strings selected! Select the string you want to delete."
你需要看看DBGrid1.SelectedRows
procedure TForm24.Button1Click(Sender: TObject);
var
BookmarkList: TBookmarkList;
Bookmark: TBookmark;
i: Integer;
begin
BookmarkList := DBGrid1.SelectedRows;
if BookmarkList.Count = 0 then
ShowMessage('No strings selected! Select the string you want to delete')
else
begin
for i := 0 to BookmarkList.Count - 1 do
begin
ClientDataSet1.GotoBookmark(BookmarkList[i]);
ClientDataSet1.Delete;
end;
end;
end;
你没有说你的网格是否设置为使用 dgRowSelect and/or dgMultiSelect 或不。如果是,则当前选定行的列表可通过 SelectedRows 属性.
作为书签列表使用
如果没有选定的记录,则此列表将为空,因此:
if myGrid.SelectedRows.Count = 0 then
// Nothing selected!
我在 DBGrid 之外有 DBGrid 和按钮 "Delete"。我如何确定用户在 DBGrid 中选择了某个字符串?因为如果打开表单并且没有在 DBGrid 中选择字符串,并且用户单击了按钮 "Delete" - 我需要向他显示警告框 "No strings selected! Select the string you want to delete."
你需要看看DBGrid1.SelectedRows
procedure TForm24.Button1Click(Sender: TObject);
var
BookmarkList: TBookmarkList;
Bookmark: TBookmark;
i: Integer;
begin
BookmarkList := DBGrid1.SelectedRows;
if BookmarkList.Count = 0 then
ShowMessage('No strings selected! Select the string you want to delete')
else
begin
for i := 0 to BookmarkList.Count - 1 do
begin
ClientDataSet1.GotoBookmark(BookmarkList[i]);
ClientDataSet1.Delete;
end;
end;
end;
你没有说你的网格是否设置为使用 dgRowSelect and/or dgMultiSelect 或不。如果是,则当前选定行的列表可通过 SelectedRows 属性.
作为书签列表使用如果没有选定的记录,则此列表将为空,因此:
if myGrid.SelectedRows.Count = 0 then
// Nothing selected!