Simple question, value not being display in DevExpress's LookupComboBox - delphi

This is a Delphi project, but I suspect DevExpress's component works similar for Delphi and .NET.
I have a DevExpress GridDBTableView, when selecting a cell in one of the column, I want a LookupComboBox to show up, where user can select an item, and the value gets display in the table cell. Simple.
I've set the column's Properties set to 'LookupComboBox'.
I have ListColumns setup with 'LocationName' and 'QuantityOnHand'.
ListSource is set to a datasource that's linked a dataset of 'LocationID', 'LocationName', and 'QuantityOnhand'.
ListFieldNames is set to 'LocationName;QuantityOnHand'
When I click on the cell, the combo box shows up with locations for me to choose, but when I choose a location, the table cell doesn't show the location name. In fact, I can't type anything in the cell.
What am I missing?
Ideally, I would like to be able to select a location from the combo box, the location name shows up in the table cell, and I can somehow store the corresponding LocationID that was selected.

I think that you should also set the column's Properties.KeyFieldName property to the KeyField of the Lookup DataSource. In this case, everything should work properly.

OK, all the answer is in the Express Editors' help file article 'Using Lookup Editors'.
The only step I missed was setting the LookupComboBox's KeyFieldNames property to 'LocationID'.

Related

Is there a way to get a cell value from the selected row in DBGrid? (Delphi)

First of all, I'm pretty new to Delphi.
I have a DBGrid connected to a DataSource and filled up with data from an SQL server. What I want to achieve is that when I press a button, it brings up a new window with comboboxes/editboxes, all filled up with the previously selected (in DBGrid) row's data and modify them and execute an UPDATE query.
In order to do that, I need the primary key value of the selected record, so my little program would know which row should it display and update.
My question is, how can I get a specific cell value (in this case, an id) of a selected record from a DBGrid?
If you know the column for the ID field you can inspect its Field property. The Fields Value will contain the current ID.

Delphi navigate through the TDBGrid using the TAB

In my DBGRID, i have a field that populated with default name of current configuration when i create new record.
When i set the dgtabs option to true, I can navigate through the grid using the TAB and SHIFT+TAB keys. I need to navigate without create new record or create new record with field populated by the current configuration name.
How can do that?
or create new record with field populated by the current configuration name.
You can do that simply by creating an OnNewRecord event handler for the dataset connected to the DBGrid and saving the configuration name to the relevant field in that.
Regarding how to avoid navigating the grid using Tab & Shift Tab opening the New Record row, a simple way, which may be acceptable (or not) to your situation is to set the DBGrid's Options.dgEditing to False. Then, the grid will not open the New Record row when Tab or Shift Tab is pressed or even if you press the Insert key in the DBGrid.
If that's not appropriate, you might take a look at my answer to this q
Focus cells in reverse order
which may give you a clue if you need it.

DELPHI : String grid header background/font color

I've created a string grid with a certain amount of columns and rows. I've also handle a right clic event on the string grid which displays a popup menu when you clic on the right button. You have some options inside this popup menu.
My question is how do i change background or police font color of a cell when i select an option from my popup menu. I know we can get the selected col using stringGrid.Col and same for the row, and i also know we ca change color on draw cell event. But i want to change the color on user action only.
For example, in my table i open up a file and i load the file content into a string grid (it's a CSV file). This file will be modified in my application from the string grid and then exported to a databse. An user can select a particular col with the right clic and then press primary key or foreign key or any other option. When he selects primary key, for example, i want to change the color of the column header so he can know which clumn is the primary key, which is the foreign key and so on. See what i mean?
PS: I am using delphi 2006 and can't change to another version.
PS: i've searched for a delphi forum on stackoverflow/exchange but didn't find the correct forum i guess
Paint the background in the desired colour in an OnDrawCell handler as you currently do.
When you need to change colours, in response to user action, force a paint cycle by calling Invalidate on the grid.
If for some reason you don't want to invalidate the entire control, calculate the rectangle that needs to be re-painted and pass it to InvalidateRect.

cxGrid expand row height to new line with enter

This is a little hard to explain so please bear with me. When I am editing a text field in one of the columns I would like to,when I hit enter, go to new line under the edited text so the grid basically expands.
Options-View-CellAutoHeight set to true expands the cell but editing is terrible.Cant
see a thing where the first line is,where it ends,etc...
Here is the grid:
I can not go after the last letter 'a' with my mouse cursor and hit enter so another line gets added. Which settings regulate this ? I know it can be done since I had a grid once and could do this.
EDIT: This requires no code just applied settings.
Just tested it with DevExpress VCL 13.2 and it can be easily done without coding (if I understood what you want to achieve).
Basically, you need to set following properties:
Assign a Memo to the Properties of your column and make sure its WantReturns property is set to true.
In your TableView set the OptionsView.CellAutoHeight property to true.
Also in your TableView, set the OptionsBehavior.EditAutoHeight to either eahEditor (editor is sized vertically to fit the content) or eahRow (the entire row is sized when editing) as needed.

TDBGrid columns design time or run time?

I am using TDBGrid for the first time.
I didn't even notice the Columns property in the object inspector and everything went just fine: the grid was filled.
Then I saw the Columns property and tried it. When I use the object insector to add items to the Columns property of the grid, they do not all of them show up at run time. To me, it looks like the FieldName property is important. It looks like it is correct, but there are no values in some columns.
If I leave this property blank (no columns at all) it seems that the control populates it itself at run time and I do see all the columns. I could live with that. When I set column titles at run time it works, but setting column width does not.
[Update] Thanks for the feedback. I am learning slowly. Now I see what is happening. I wanted three of the five columns to be calculated. Two are gotten from INNER JOINs and the third from an SQL 'cast' of SELECT ... FROM_UNIXTIME(<table>.time_stamp).
If I do not define the columns at design time then these values are populated at run time when I execute my SELECT. Cnn anyone tell me how to set things up at design time? Thanks
There is no difference in functionality between runtime and designtime set up columns. That is: what can be done designtime can also be done runtime, and vice versa.
When te Columns property is kept empty, the grid fills it by default with all fields it finds in the linked dataset, once the dataset is opened. All column specific settings, such as alignment, width, title caption, etc... are set to default, based on the type, length and name of the corresponding field. This is the lazy way which sure could be sufficient.
You could deside to use your own setup or modification of the columns property, for one or more of the following reasons:
Change the order of the dataset fields in which they must appear in the grid,
Truncate the width of text fields (especially VarChar fields or Char fields with a large length normally result in colums that are too wide for normal presentation and/or user interaction),
Change the alignment of the fields (normally numeric fields are right aligned by default),
Hide one or more fields from the dataset,
Etc...
These own settings can be done desingtime as well as runtime.
Using the designtime columns editor is the preferred and RAD way in need of these customizations. Open the editor by double clicking the grid or the property, or via the grid's context menu. If the linked dataset is active then the command Add all fields is enabled, which does exactly the same as if you did not select any field at all, i.e. the default behaviour as described in the second paragraph.
The best way to define the columns on a dbGrid is to doubleclick the dataset in order to create variables that the form knows about (persistent fields). You can edit various properties of these variables such as DisplayLabel, DisplayWidth and DisplayFormat.
You can also add calculated fields by double clicking on the dialog box which appears when you double click on the client dataset.

Resources