eduardosuruagy Posted August 12, 2019 Posted August 12, 2019 How to delete dbgrid columns? Is this correct? dbgrid.Columns . Destroy; Quote
Sherzod Posted August 12, 2019 Posted August 12, 2019 9 minutes ago, eduardosuruagy said: How to delete dbgrid columns? Is this correct? dbgrid.Columns . Destroy; Hi, Can you clarify in more detail? What do you need that for? Quote
eduardosuruagy Posted August 12, 2019 Author Posted August 12, 2019 I would like to delete a certain column from my grid at runtime, but I already did. Thank you! Quote
easegura777 Posted April 14, 2020 Posted April 14, 2020 On 8/12/2019 at 7:22 AM, eduardosuruagy said: I would like to delete a certain column from my grid at runtime, but I already did. Thank you! Hi, Could you share how you did it? thanks Quote
erich.wanker Posted April 14, 2020 Posted April 14, 2020 hi .. i use following code (found it here in the forum - did not know the original Poster of the code) works perfekt .. the user can select at runtime the position, the size and the visibility of colums .. procedure TyourForm_orFrame.loadGridLayout; var Lines: TStringList; columnInfo: TStringList; lineCtr: Integer; colIdx: Integer; cnt: Integer; FileName: String; begin FileName := uniservermodule.FilesFolderPath + '/Usersettings/user_' + UniMainModule.UserNumber + '_setting_grid2.txt'; if FileExists(FileName) then begin try Lines := TStringList.Create; columnInfo := TStringList.Create; Lines.LoadFromFile(FileName); for lineCtr := 0 to Lines.Count - 1 do begin if trim(Lines[lineCtr]) <> '' then begin StringExplode(Lines[lineCtr], '~ ', columnInfo); cnt := Mydbgrid.Columns.Count; // go through all the columns, looking for the one we are currently working on for colIdx := 0 to cnt - 1 do begin // once found, set its width and title, then its index (order) if Mydbgrid.Columns[colIdx].FieldName = columnInfo[1] then begin Mydbgrid.Columns[colIdx].Width := strtoint(columnInfo[3]); Mydbgrid.Columns[colIdx].Title.Caption := columnInfo[2]; if columnInfo[4] = 'true' then Mydbgrid.Columns[colIdx].Visible := true else Mydbgrid.Columns[colIdx].Visible := false; // do the index assignment last! // ignore the index specified in the file. use its line Mydbgrid.Columns[colIdx].Index := lineCtr; // StrToInt(columnInfo[0]); order instead end; // if end; end; end; finally Lines.Free; if assigned(columnInfo) then columnInfo.Free; end; end; end; procedure TyourForm_orFrame.saveGridLayout; var Lines: TStringList; i: Integer; my_visible: String; FileName: String; begin FileName := uniservermodule.FilesFolderPath + '/Usersettings/user_' + UniMainModule.UserNumber + '_setting_grid2.txt'; try Lines := TStringList.Create; with Mydbgrid do begin for i := 0 to Mydbgrid.Columns.Count - 1 do begin if Mydbgrid.Columns.Visible = true then my_visible := 'true' else my_visible := 'false'; Lines.Add(inttostr(Mydbgrid.Columns.Index) + '~ ' + Mydbgrid.Columns.DisplayName + '~ ' + Mydbgrid.Columns.Title.Caption + '~ ' + inttostr(Mydbgrid.Columns.Width) + '~ ' + my_visible); end; end; Lines.SaveToFile(FileName); finally Lines.Free; end; end; Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.