I am using the cxGrid. I have a field (column) in my grid that is of boolean type (true/false) represented in the grid as a checkbox. How can I make all the checkboxes in the column checked (or unchecked) on button click ?
it looks like this :
Now I would like, on button click, to turn those 3 checkboxes checked BEFORE I save everything..
DATA on the left(USERS) comes from a table, the data on the right is from a query. The SAVE of everything goes to a separate LOG table.
When I hit 'Check all' button,the result :
I could run the update query : update MYFIELD set SELECTED = '2';
but I am more interested in manipulating the grid itself.Something simple...
You will have to add a button or pop up menu somewhere on your form to accept the check all 'command', or maybe even place a checkbox in your column header. Then go through your underlying dataset and set all field values. Don't forget a DisableControls/EnableControls.
added an extra field to my table (boolean type) and changed its property in the cxGrid to that of a checkbox.Then on button click:
with uniquery1 do begin
Active:=False;
sql.Clear;
SQL.Add('update users set selected = 0'); //or '1'
execSql;
end;
Uniquery1.Refresh;
this I found was the easiest way ....
Related
I want to create a Yes/No row in a table, the row would be called 'prepayment'. So, if there is one, and you check 'Yes' in the form, I want some textbox to appear -- so you could type in the sum of prepayment. Is there some way to do it the way that textbox to type in the sum wouldn't be visible in the form unless you check 'Yes'?
I didn't really try anything yet. Just have no idea how to do it...
Solomon,
Set the Visible property on the Textbox to No.
Create an On_Click event for the Checkbox.
The code for the On_Click event should change the Textbox Visible property to Yes. You might also want to check the current setting of the Textbox Visible property so you can hide it if they uncheck the Checkbox.
I would like to change DBgrid row value with outside data, how to achieve that?
For example i would like to add Tedit value into dbgrid selected row column(for example 5) via button click.
Also, i would like to add value from 1 dbgrid to another dbgrid.(Add to an existing number, not replace).
Suppose you have a dataset connected to db-aware controls like TDBEdit and TDBGrid via a TDataSource. Delphi's db-aware controls are basically the default ones which come with Delphi and are displayed on the Data controls tab of its Component Palette plus any 3rd-party ones that you install. The reason they are called db-aware is because they are written so that the values they display are automatically derived from the related fields of the dataset.
Also suppose that the dataset is called Table1 and has a CustomerName field that you want to change. The simplest code which will achieve that is something like:
Table1.Edit; // put table one into dsEdit state so that field values can be changes
Table1.FieldByName('CustomerName').AsString := 'Jones';
Table1.Post; // save the change(s) to Table1
More optimal code might be
Table1.Edit;
try
Table1.DisableControls; // this prevents the db-aware controls updating on-screen while the changes are made
Table1.FieldByName('CustomerName').AsString := 'Jones';
Table1.FieldByName('CustomeCountry').AsString := 'DE#;
finally
Table1.Post;
Table1.EnableControls; // Eable screen updating od the db-aware controls again
end;
That would update the values displayed in DBEdit controls linked to the CustomerName and CustomerCountry fields and in the CustomerName and CustomerCountry cells of the current (i.e. highlighted) row in the DBGrid, because the current row in the DBGrid always tracks the current row in the connected dataset.
If you really do want to update a given column from a TEdit's text you could do that like this:
Table1.Edit;
DBGrid1.Columns[5].Field.AsString := Edit1.Text;
Table1.Post;
I have a form with 2 RadioButtons(with same GroupName) and I need to save 'A'(if RadioButton1 is selected) or 'I'(if RadioButton2 is selected) in the field Status using LiveBindings.
One Component to One Field is easy, but in this case I have two components getting and setting values from one field.
I created a function that returns the radiobutton selecting through Groupname and fill the field manually, but I wanted something more automatic.
Thanks in advanced!
Here are the steps to accomplish this.
Create your two RadioButtons, call it RadioButton1 and RadioButton2.
Set their GroupName property to the same string for both radio buttons.
Right click your 1st radio button and select Bind Visually...
In the LiveBindings designer, right click your radio button and select Bindable Members, and then select the checkbox IsChecked followed by clicking the ok button.
Still within the Live Bindings designer, Now drag a link between the IsChecked property and the field you wish to bind to (note this can be a string field).
Repeat steps 4 and 5 for the other Radio Button.
Now you are almost down, but you need to convert the string to a boolean so that the IsChecked property will have a boolean value. To do this, select the binding link from the LiveBindings Designer for your radio button. Then in its CustomFormat property, assign the following string
IfThen(ToStr(%s)="Poor",True, False)
This will allow the radio button to be checked when the underlying database value is 'Poor'
Do the same for your other radio button, except use a different string
IfThen(ToStr(%s)="Excellent",True, False)
Now to give the radio buttons the ability to change the underlying database field, you will need to attach code to perform this. Let us use the radio button's OnClick event (attach to both radio buttons). This code assumes your underlying dataset is named FDCustomer, and your field is named Status. Note that the radio button is not checked yet at the time of the event, so we look for IsChecked to be false.
if Sender = RadioButton1 then
begin
if not TRadioButton(Sender).IsChecked then // checking
begin
fdcustomer.Edit;
fdcustomer.FieldByName('Status').AsString:= 'Poor';
end;
end
else if Sender = RadioButton2 then
begin
if not TRadioButton(Sender).IsChecked then
begin
fdcustomer.Edit;
fdcustomer.FieldByName('Status').AsString:= 'Excellent';
end;
end;
I have a TDBComboBox on my form. Right now it's hooked up to a database field that can only contain a Y or an N.
I'd like to pretty it up a little, and have it instead show Yes or No. How can I do this?
To solutions for me was:
Switch the control (YesNoCombo) to TDBLookupCombobox
On the form in the Design view, create a TClientDataSet (called YesNoCDS) with two fields
DisplayValue
DatabaseValue
Right-Click on YesNoCDS and select Create Dataset
Append the data for YesNoCDS in the FormShow event (this seems like a kludge, but I don't see a way to do that in the Design view)
Create a TDataSource on the form called YesNoDS and set its DataSet to YesNoCDS
On YesNoCombo, set the ListSource to YesNoDS, and then set the List Field to DisplayValue and the KeyField to DatabaseValue
I'm making a simple program for use in automotive parts shop. Here's how it's supposed to look: Link
The problem is the small window on the left. It should be opened when double clicked on any of the rows in DBGrid in the main window, and it should show all of the selected item's characteristics in DBEdit fields. If the Save button is clicked it should save the changes from the DBEdit fields into the database, but otherwise it should just ignore the changes.
I succeeded opening another form by double click on a field in DBGrid by using this code:
procedure TForm1.DBGrid1DblClick(Sender: TObject);
begin
if not Assigned(Form2)
then Form2 := TForm2.Create(Application);
Form2.Show;
end;
The only problem now is how to get the program to detect which row in the DBGrid is selected and then show its contents in DBEdit fields in the smaller window.
Can anyone tell me how to do this, please?
Thanks!
Just add the TDBEdits to TForm2, and connect them to the same DataSource as the DBGrid is using. They will automatically show the contents of the same row that is selected in the DBGrid, and you can edit or insert into the DataSource's DataSet and have the new or changed data appear in the DBGrid automatically.
There are many ways to achieve this. I'll describe two:
If you link the DBEdits in the little window to the same DataSource as the DBGrid's, then you are all set
OR
You can pass whatever info you want inside DBGrid1DblClick from Form1 to Form2. This option, by itself, has many possibilities.
Update
For the DataSource to be visible in Form2, unit to make Form2's unit use Form1's unit.