PDA

View Full Version : Quick Delphi Control Question...



Xorcist
16-11-2004, 11:37 PM
What control should I use if I want to create a list of selectable strings where each string resides in it's own column (left to right). An example of this would be the attachement list in Outlook Express. I can't seem to find a control that will do this nicely without scrollbars. Basically I want a horizontal listbox...

cairnswm
17-11-2004, 06:49 AM
What about List view?

Or use a liust box but owner draw a sub list into a single line with your own formatting.

WILL
17-11-2004, 07:50 AM
If you are really stuck on Standard VCL/CLX components youcan always try TMS Software... http://www.tmssoftware.com/

They have a nice selection for Delphi/Kylix components. And they are working to support Delphi 2005 for all existing components offered.

Xorcist
19-11-2004, 09:03 AM
I've never done any ownerdraw stuff before... does anyone have any links to soem tutorials or examples?

Lightning
19-11-2004, 03:41 PM
What about StringGrid ?
Look at the sources, i have made some components myself and i can tell you the first step is harder :)

Xorcist
19-11-2004, 11:45 PM
StringGrid seems to work okay, but I'm having trouble getting the column widths to align to the size of the string. Strings that are too small leave a lot of space, ones that are too big get cut off. What is the easiest way to determine the pixel length of a string?

Doh' seems it's real easy... Canvas.TextWidth('string goes here') + 5;

Seperate question though... when I click a cell it gets focus, but it doesn't darken as a selection. Is there a way to get the cell to highligh as a selection. I've checked through the methods provided for a TStringGrid but haven't found what I'm looking for.

Xorcist
20-11-2004, 02:37 AM
Took me a bit, but I think I go it...

I used the onDrawCell Event and checked for a selection to draw gray as the background, here is the code I used.

[background=#FFFFFF][comment=#8080FF][normal=#000080]
[number=#C00000][reserved=#000000][string=#00C000]
procedure Tfrm_Main.grd_AttachDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
var
S: string;
begin
with (Sender as TStringGrid) do begin
S := Cells[ACol, ARow];
if (gdSelected in State) then begin
with Canvas do begin
Brush.Color := clLtGray;
FillRect(Rect);
TextOut(Rect.Left + 2, Rect.Top + 2, S);
end;
end;
end;
end;