[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

multi column combo box

Posted on 2005-05-11
10
Medium Priority
?
506 Views
Last Modified: 2010-04-05
Looking for a way to place check boxes in a multi column combo box and mark the check box as per condition true or false
example list:
Col 1, Col 2, Col 3, Col 4
1st list item, check box true, check box false, check box true
2nd list item, check box false, check box false, check box true

The quantity of check box columns varies depending on conditions

Any ideas?
0
Comment
Question by:RonOsborne
10 Comments
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 13983544
Are you sure you want a Comobobox? sounds more like a TPopupMenu thing
0
 
LVL 11

Expert Comment

by:calinutz
ID: 13984179
I recomend that you use a form that would pop up on MouseDown event (for example).
And on the form you could place a stringGrid (alterable on runtime). And you can draw the CheckBoxes insite the Cells of the StringGrid and make them react to your clicks.
As for ComboBox with multiple columns and multiple checkBoxes on a row... I never heard of such a component to exist for delphi at least... Perhaps if you take the time and build it yourself.
Anyway, it sounds quite complicated to create such a component.
So my suggestion is to try the StringGrid thing. It can be done so well that you will not make a difference between the normal comboBox and the StringGrid form.
Cheers
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13984273
I would recommend using the first part of Calinutz's answer and create a totally new form on the mousedown event.
Instead of a stringgrid though you could use a CheckListBox and change the number of columns you want to use depending on the information to display.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 11

Expert Comment

by:calinutz
ID: 13984403
You have my code here on using a StringGrid on a new form (Form2) that is called (in this example) in the ButtonClick Event. You can do it whereever you want.
So In my example I create a stringGrid and on the rows 2,3,4 a place CheckBoxes.
I also show you in the code how to add new rows containing checkBoxes on the same rows... So just doubleClick on the StringGrid and a new row will show up containing the checkBoxes.

Here are the forms...

object Form1: TForm1
  Left = 154
  Top = 233
  Width = 211
  Height = 99
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object BitBtn1: TBitBtn
    Left = 80
    Top = 32
    Width = 75
    Height = 25
    Caption = 'BitBtn1'
    TabOrder = 0
    OnClick = BitBtn1Click
  end
end

// and form2

object Form2: TForm2
  Left = 327
  Top = 243
  BorderStyle = bsNone
  Caption = 'Form2'
  ClientHeight = 164
  ClientWidth = 347
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 347
    Height = 164
    Align = alClient
    BevelInner = bvRaised
    BevelOuter = bvLowered
    Caption = 'Panel1'
    TabOrder = 0
    object CheckBox1: TCheckBox
      Left = 248
      Top = 36
      Width = 97
      Height = 17
      Caption = 'CheckBox1'
      TabOrder = 1
    end
    object StringGrid1: TStringGrid
      Left = 2
      Top = 2
      Width = 343
      Height = 160
      Align = alClient
      BorderStyle = bsNone
      Color = clBtnFace
      DefaultRowHeight = 16
      FixedCols = 0
      FixedRows = 0
      Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goRowSelect]
      TabOrder = 0
      OnDblClick = StringGrid1DblClick
      OnDrawCell = StringGrid1DrawCell
      OnKeyUp = StringGrid1KeyUp
    end
  end
end

0
 
LVL 11

Expert Comment

by:calinutz
ID: 13984405
And now the Code:
//For Form1

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons;

type
  TForm1 = class(TForm)
    BitBtn1: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Form2.Top:=Mouse.CursorPos.Y;
Form2.Left:=Mouse.CursorPos.X;
Form2.StringGrid1.Cells[0,0]:='Test1';
Form2.StringGrid1.Cells[1,0]:='Test2';
Form2.StringGrid1.Cells[2,0]:='Test3';

Form2.ShowModal;
end;

end.
0
 
LVL 11

Expert Comment

by:calinutz
ID: 13984418
//And now the Form with the checkBoxes...
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, ExtCtrls, StdCtrls;

type
  TForm2 = class(TForm)
    Panel1: TPanel;
    StringGrid1: TStringGrid;
    CheckBox1: TCheckBox;
    procedure StringGrid1KeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure StringGrid1DblClick(Sender: TObject);
  private
  procedure clean_previus_buffer;
  procedure set_checkbox_alignment;
  procedure AddCheckBoxes(rowu:Integer);

    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.StringGrid1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
If key=27 then Close;
end;



procedure TForm2.clean_previus_buffer;
var
  NewCV,NewDet,NewCheckBox: TCheckBox;
  i: Integer;
begin
  for i := 1 to StringGrid1.RowCount-1 do
  begin
    NewCheckBox := (StringGrid1.Objects[2, i] as TCheckBox);
    if NewCheckBox <> nil then
    begin
      NewCheckBox.Visible := false;
      StringGrid1.Objects[2, i] := nil;
    end;
  end;

  for i := 1 to StringGrid1.RowCount-1 do
  begin
    NewDet := (StringGrid1.Objects[3, i] as TCheckBox);
    if NewDet <> nil then
    begin
      NewDet.Visible := false;
      StringGrid1.Objects[3, i] := nil;
    end;
  end;

  for i := 1 to StringGrid1.RowCount-1 do
  begin
    NewCV := (StringGrid1.Objects[4, i] as TCheckBox);
    if NewCV <> nil then
    begin
      NewCV.Visible := false;
      StringGrid1.Objects[4, i] := nil;
    end;
  end;

end;

procedure TForm2.set_checkbox_alignment;
var
  NewCV,NewDet,NewCheckBox: TCheckBox;
  Rect: TRect;
  i: Integer;
begin
  for i := 1 to StringGrid1.RowCount-1 do
  begin
    NewCheckBox := (StringGrid1.Objects[2, i] as TCheckBox);
    if NewCheckBox <> nil then
    begin
      Rect := StringGrid1.CellRect(2, i);
      NewCheckBox.Left := StringGrid1.Left + Rect.Left + 2;
      NewCheckBox.Top := StringGrid1.Top + Rect.Top + 2;
      NewCheckBox.Width := Rect.Right - Rect.Left;
      NewCheckBox.Height := Rect.Bottom - Rect.Top;
      NewCheckBox.Visible := True;
    end;
    NewCheckBox := (StringGrid1.Objects[3, i] as TCheckBox);
    if NewCheckBox <> nil then
    begin
      Rect := StringGrid1.CellRect(3, i);
      NewCheckBox.Left := StringGrid1.Left + Rect.Left + 2;
      NewCheckBox.Top := StringGrid1.Top + Rect.Top + 2;
      NewCheckBox.Width := Rect.Right - Rect.Left;
      NewCheckBox.Height := Rect.Bottom - Rect.Top;
      NewCheckBox.Visible := True;
    end;
    NewCheckBox := (StringGrid1.Objects[4, i] as TCheckBox);
    if NewCheckBox <> nil then
    begin
      Rect := StringGrid1.CellRect(4, i);
      NewCheckBox.Left := StringGrid1.Left + Rect.Left + 2;
      NewCheckBox.Top := StringGrid1.Top + Rect.Top + 2;
      NewCheckBox.Width := Rect.Right - Rect.Left;
      NewCheckBox.Height := Rect.Bottom - Rect.Top;
      NewCheckBox.Visible := True;
    end;
  end;
end;


procedure TForm2.AddCheckBoxes(Rowu:Integer);
var
  i: Integer;
  NewCV,NewDet,NewCheckBox: TCheckBox;
begin
i:=rowu;
  clean_previus_buffer;
  begin
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    NewCheckBox := TCheckBox.Create(Application);
    NewCheckBox.Width := 0;
    NewCheckBox.Visible := false;
    NewCheckBox.Caption := 'First';
    NewCheckBox.Color := clWindow;
    NewCheckBox.Tag := i;
    NewCheckBox.Ctl3D:=false;
//    NewCheckBox.OnClick :=CheckBoxXClick;
    NewCheckBox.Parent := Self;
    StringGrid1.Objects[2, i] := NewCheckBox;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    NewDet := TCheckBox.Create(Application);
    NewDet.Width := 0;
    NewDet.Visible := false;
    NewDet.Caption := 'Second';
    NewDet.Color := clWindow;
    NewDet.Tag := i;
//    NewDet.OnClick := CheckBoxYClick;
    NewDet.Ctl3D:=false;
    NewDet.Parent := Self;
    StringGrid1.Objects[3, i] := NewDet;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    NewCV := TCheckBox.Create(Application);
    NewCV.Width := 0;
    NewCV.Visible := false;
    NewCV.Caption := 'Third';
    NewCV.Color := clWindow;
    NewCV.Tag := i;
//    NewCV.OnClick := CheckBoxZClick;
    NewCV.Ctl3D:=false;
//    NewCV.Enabled:=false;
    NewCV.Parent := Self;
    StringGrid1.Objects[4, i] := NewCV;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    StringGrid1.RowCount := i+1;
  end;
  set_checkbox_alignment;
end;


procedure TForm2.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
 s: string;
begin
inherited;
  if not (gdFixed in State) then
    set_checkbox_alignment;
end;


procedure TForm2.FormShow(Sender: TObject);
begin
//AddCheckBoxes;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
StringGrid1.RowCount:=3;
  AddCheckBoxes(0);
  AddCheckBoxes(1);
  AddCheckBoxes(2);

end;

procedure TForm2.StringGrid1DblClick(Sender: TObject);
var
 r:integer;
 NewCheckBox,NewDet,NewCV:TCheckBox;
begin
r:=StringGrid1.RowCount;
StringGrid1.RowCount:=r+1;
    NewCheckBox := TCheckBox.Create(Application);
    NewCheckBox.Width := 0;
    NewCheckBox.Visible := false;
    NewCheckBox.Caption := 'rate';
    NewCheckBox.Color := clWindow;
    NewCheckBox.Tag := r;
    NewCheckBox.Ctl3D:=false;
//    NewCheckBox.OnClick := CheckBoxXClick;
    NewCheckBox.Parent := Self;
    StringGrid1.Objects[2, r] := NewCheckBox;

    NewDet := TCheckBox.Create(Application);
    NewDet.Width := 0;
    NewDet.Visible := false;
    NewDet.Caption := 'Detalii';
    NewDet.Color := clWindow;
    NewDet.Tag := r;
//    NewDet.OnClick := CheckBoxYClick;
    NewDet.Ctl3D:=false;
    NewDet.Parent := Self;
    StringGrid1.Objects[3, r] := NewDet;

    NewCV := TCheckBox.Create(Application);
    NewCV.Width := 0;
    NewCV.Visible := false;
    NewCV.Caption := 'CV';
    NewCV.Color := clWindow;
    NewCV.Tag := r;
//    NewCV.OnClick := CheckBoxZClick;
    NewCV.Ctl3D:=false;
//    NewCV.Enabled:=false;
    NewCV.Parent := Self;
    StringGrid1.Objects[4, r] := NewCV;
end;

end.
0
 
LVL 11

Accepted Solution

by:
calinutz earned 1500 total points
ID: 13984428
I hope my code helped...
For adding new columns to the StringGrid... It's quite simple  since you only have to change StringGrid1.ColCount:=StringGrid1.ColCount+1 //or something like that

I showed you how to add on runtime rows containing checkBoxes..., it's similar with the columns.
It's easyer to build the StringGrid and just show it aND work with the events of the StringGrid and CheckBoxes
Now.. it's up to you to modify it to fit your needs.
0
 

Author Comment

by:RonOsborne
ID: 13985832
To calinutz
Would you like to write that as a component for 500 points?
Just asking!
0
 
LVL 11

Expert Comment

by:calinutz
ID: 13986489
Did you succeed building your thing?
Sorry I do not have the time to write components these days...
But the above question was not for making a component, am I right?
0
 

Author Comment

by:RonOsborne
ID: 13986840
I have not fully implemented it yet
I'll work something out
I was just looking for a quick fix with the component, a bit of a rush job
Thanks again

posting another question soon if you want to have a go at it
Title will be
Best path to Windows Mobile
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question