Add calculated column with checkboxes to datagrid - delphi

In my application I have a TcxGrid (devexpress datagrid) that displays the data returned from a stored procedure.
Now I would like to add a column showing checkboxes from which the values cannot come from the database but are calculated internally.
When the checkboxes are clicked, some internal logic needs to be triggered.
Any suggestions?

#boris, I recommend you use the Support Center site of DevExpress for this type of question, there are thousands of articles to DevExpress products.
Anyway I leave here a link to something that might help ;)
How to set up an unbound item in a data-aware View

Are you creating the view at runtime or at designtime?
I sort of cheated when I did this at runtime, and returned a static value as one column from my query:
select false as processed,col1,col2 from table where true
I could then safely attach the dataset, and I had my new column to play with.
You would then perhaps use the properties.onChange or properties.onEditValueChanged for your logic code.

Related

Columns order in ListGrid Smartgwt

How can I programmatically change the order of columns in ListGrid? I have search for an appropriate method in javadoc but found nothing. Is it possible?
Check out setViewState method and this example that saves and restores grid preferences (including column order). So in short, you are interested in getting viewState string from ListGrid data and using it. Remember to redraw grid after setting new viewState.

How to add a non-bound column to a DevExpress DB QuantumGrid

I am using these components:
UniDac for connection to mysql database
DevExpress for QuantumGrid
IDE:
Embarcadero Rad Studio XE2
I have a cxGrid component with one level and a cxGrid1DBTableView specified as the level's View. I can get data from my database and edit it in the grid. I want to add a column that is not in the bound DataSet. When I specify the Column properties value as CheckBox I can see the column but I can't change the value from unchecked to checked by clicking it. The field doesn't have a DataBinding assigned to it. I tried other types of Properties but all are the same I cant change the row value in the grid.
I've been searching for a way to fix this for couple of days, so im hoping you guys can help me.
Are you trying to add a checkbox item that does not have a database field behind it? I have this on one of my forms.
In addition to setting the Properties to "Checkbox" you need to set the DataBinding -> ValueType to "Boolean". The DataBinding->FieldName can be left blank.
To access the values or change their defaults you can use the DataController like this:
View.DataController.Values[i, CheckBoxFieldIndex] := true;
In addition you need to set
DataController.DataModeController.SmartRefresh := true;
To set that option you will also need a KeyField defined for the Controller (DataController.KeyFieldNames)
Setting the SmartRefresh to true will prevent the grid from trying to get an updated value from the underlying dataset. You need to prevent the refresh or the value for the non-bound column will be set back to Null. This comes with some restriction on how you update your dataset. Any changes made to the data in code will not be reflected by the grid unless you explicitly refresh the grid.
You also have to fill the field View.DataController.KeyFieldNames with one of the datasets fields. At least I need it in Delphi 7.

AutoID Field in Many-to-Many, Insert Using TDataSet / Query (Delphi / MSAccess)

I have a database of "Items", which are assigned to multiple "Categories". Categories can have multiple items, and vice versa. The relevant portion of the database structure is as follows:
[tblItem]
ItemID (AutoNumber)
MainText (Text)
[tblCategory]
CategoryID (AutoNumber)
Name (Text)
[tblItemCategory]
ItemID (Long Integer)
CategoryID (Long Integer)
I want to build a panel component which shows a category name at the top, with a databound grid of items belonging to that grid below. There will be many instances of this panel component, and the end-user should be able to create a new item and simultaneously assign it to the category in question from any one of them.
In MS Access, it's possible to create a nested form, with the "child" one databound to a query which is "MasterFields" linked to a databound "Category" field on the "parent" form, such that the grid of items changes as the Category field is changed. This Items grid can also easily have new records added to it, with both the ItemID (in tblItem AND table tblItemCategory) and the linked CategoryID field (in tblItemCategory) being populated automatically.
The query for that Access form's grid is:
SELECT tblItemCategory.CategoryID, tblItem.*
FROM tblItemCategory LEFT JOIN tblItem ON tblItemCategory.ItemID = tblItem.ItemID
ORDER BY tblItemCategory.CategoryID;
If I try the same thing in Delphi, the ItemID AutoNumber field doesn't get populated, resulting in the following error:
..exception class EOleException with message 'The field 'tblItemCategory.ItemID' cannot contain a Null value because the Required property for this field is set to True. Enter a value in this field'.
..and the ItemID field is accordingly blank in the grid.
Is there a way to get Delphi/ADO to handle the behind-the-scenes two-table ItemID population as easily/neatly as Access does, without manually handling it programmatically? If not, what's the best/most elegant way to handle it programmatically?
I'd like to keep whatever solution I end up with as closely tied to the conventional TDataSet / TDataSource approach as possible, as I use a number of different kinds of databound controls, all of which will have to deal with this same data structure.
(Note: I'm using Delphi 2007 and an MSAccess 2000 format MDB file.)
Pretty much the same way. Theres's master source and master fields properties, so you just chain detail to master.
So mastersource would be Customer, Detail Source, Orders linked by CustomerID.
Dead easy to show this, but hard to explain.
Some other bloke wrote it all out though.
Master Detail Forms And Delphi
If you want to add new records to the tables via the grid, then you will have to use the BeforePost method of the underlying query in order to obtain the new key, which you then insert manually into the link table along with the category id.
I admit that I never write code with editable (and insertable) grids so my answer may need a little tweaking.

Delphi: TAdoTable.Insert not really an Insert?

I have two ADO Tables linked as master/details tables, tblCategory (master) and tblItems (details). Both tables have its own grid, and displayed in the same form. I also have data aware controls (dbedits).
Say, currently I'm at: Category=Books, No of Items=10 records, and pointing at record number 5 in the grid. I want to add a new record to the item, so I use:
tblItems.Insert;
The problem is, instead of adding a new row, the grid and the db aware controls are showing the current record (rec No 5). Not inly that, it seems the record is in edit mode too. After I cancel it and repeat the Insert command, only then the new row appeared.
How to fix this, so each time I use tblItems.Insert it always add a new and empty row :)
Nevermind, I think I know what caused it. It's the db aware controls. After the insert command, user will input data. This makes the db aware control receives focus and it automatically sets its position to the current record and displays it.
The solution is to use non-db-aware controls instead, and set the behavior programatically

Showing many tables in many dropdown lists. c#, asp.net-mvc, linq2sql

I want to use an example to explain what I want.
Assume I've following DB design:
Item (id, name, categoryID);
Category (id, name);
When user wants to create an Item (fill in form), I'll give a list of categories in a dropdownlist, and when user chooses one of the categories ASP.NET MVC will automatically bind categoryID, to the selected one. I need to present same dropdown list when editing the item with correct selected one.
Question:
But my DB is very big, and it requires around 30-40 (maybe even more) category-like tables, that contain just "id" and "name", and all tables need to be shown in dropdown list while creating some other object, and also needs to be presented while editing the object. Definitely above schema doesn't work, because it's tedious to write same logic 100 times with just different table names. (I'm using Linq2SQL)
Currently my solution is:
Make a view that's based in all such tables and in application I just call a function that construction dropdownlist from that single view. But it's still tedious to change view definition everytime I add a new table.
Do you guys think of a better solution for this tedious work, possibly using reflection or some other tecnologies.
It is not a problem "Definitely above schema doesn't work, because it's tedious to write same logic 100 times with just different table names."
If I were you, I will mark an addition interface on these class using "partial class" feature.
Then, I will write few extension method for the partial class.
If anyone interested in the solution:
I've used reflection to solve this problem.
I use reflection over DataContext to get the Table (by string name), and get its fields and construct the optionlist.

Resources