I've got a table in DB with details about some goods. Goods might be fillable, therefore we can also add text into it. So I wish to dynamically generate a listing of checkboxes associated with info in table as well as some checkboxes should be with TEdit component to create a possible ways to add text for this item. So how do i get it done? What component must i use? I determine that TTreeView is nearly enough, however it does not let it "draw" TEdit near checkboxes. I am using Delphi 2010. Thanks ahead of time! Expect your help!
Basically read your question properly, you want to create some controls on the form in line with the items in table. Within the following example I've assumed for you to do this in line with the items in the present record inside a TDBGrid, so you will need to adapt when needed.
The example assumes an application having a TDBGrid along with a TPanel (Panel1) which will contain the controls produced at run time.
The TDBGrid is going to be attached to a TDataSource component which is going to be attached to some TDataSet descendant for that table/query using the information. The TDataSource includes a OnDataChanged event. The wedding will get triggered once the data inside a area changes or once the current record within the dataset changes. So that you can use that to alter the controls because the current record changes.
procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField); var i: Integer; Chk: TCheckBox; Edit: TEdit; begin // When the Field is assigned, the call is the result of a change in the field. // When the Field is unassigned, the call is the result of changing the current record. if Assigned(Field) then Exit; // Remove controls on panel for i := Panel1.ControlCount - 1 downto 0 do Panel1.Controls[i].Free; // Add controls on panel for current record if True then // Replace this with condition based on contents of current record (if any!) begin Chk := TCheckBox.Create(Self); // Set Owner, so it is freed when form is closed. Chk.Parent := Panel1; // Set Parent, so the control is shown. Chk.Left := FLeftIndent; // Create FLeftIndent as a member field of the form, set value in OnCreate. Chk.Top := FNextTop; // Create FNextTop as a member field of the form. Inc(FNextTop, FSpacing); // Create FSpacing as a member field of the form, set value in OnCreate. if True then // Replace this with condition that dictates creation of Edit begin Edit := TEdit.Create(Self); Edit.Parent := Panel1; Edit.Left := Chk.Left + Chk.Width + FSpacing; Edit.Top := Chk.Top; // Add offset as needed for proper alignment of CheckBox and Edit. end; end; end;
Please be aware that if you don't have other checkboxes or edits around the form, you'll have to range from the proper vcl models yourself. The simplest method of doing that's to decrease them around the form, save the shape after which remove the controls again.
try this example about producing checkbox on runtimehpe it will help you'll have to customize the position dynamically. you may either produce a new component wich includes checkbox with Edit onto it or produce the TEdit dynamically where you really need it.
Consider creating a range of TCheckbox and something of TEdit and hang the visible property of every Edit using something similar to IsEditNeeded boolean function that you code the circumstances if the Edit area is required.
I'd be enticed to utilize a gridview like ExGridView, and allow it to draw my checkboxes, and perform the "edit" controls for every row, for me personally. However, if you want an edit box, rather than a power grid, you might consider using a control-power grid approach (1 checkbox + 1 edit control, inside a control-power grid).