as a follow up question to my previous one. I can edit the DBMemo's now.
However they always seem to have the values from the very first row in the table.
I've done a DBMemo1.Text = ''
I've done a locate on the DataSet underneath to see if it would clear it. but no.
What do I need to do to have that empty and type something in to insert it?
Like any other data-aware control, the memo is bound to the values from the current row in the table. Try putting a TDBNavigator and a TDBGrid on your form so you can play around with the current record and see what's going on. If you want to create an empty row to insert into it, you need to call Insert or Append on the dataset, or click the + symbol on the TDBNavigator. This creates a new, blank row in the dataset and sets it to the current row.
You probably need to add a new row to the dataset.
DataSet.Append;
I saw your last question and I believe the following tutorial will help you:
http://delphi.about.com/od/database/a/databasecourse_2.htm
To clear the text from DBMemo you should either Insert, Append or Delete+Insert/Append on your data set. Mason explained you very well that you need to have a 'navigator' for your data set. Follow the examples provided here:
http://delphi.about.com/od/database/ss/dbcourse_browse.htm
Best regards,
Radu
Related
How do people tend to let users re-order the grid columns and save that ordering for later?
The only way I can think of to do it, at least in Vaadin 7, is:
Listen for column re-ordering via addColumnReorderListener(…)
When re-order triggered, if user initiated, get columns from getColumns() and save to DB with any identifying information
When pull Grid back up, read grid ordering from DB and apply the same order with setColumnOrder(columns)
So is there a better way to do this? I just checked the Directory, could not find anything obvious to make this easier. Just looking for how others have addressed this user requirement. If Vaadin 14 already supports such actions a little easier, that would be good to know as well, as it might give me some ideas on how to get that ability short term before I can upgrade to Vaadin 14.
For a more customizable grid you can (in addition to what you've already done) add a button that opens a dialog that lists all possible columnnames, together with a checkbox.
Unchecking the checkbox removes the column, checking the checkbox adds the column.
Even more comfortable is when the dialog lists all available columns in a Grid with draggable rows and editable checkboxes, so that the user can show, hide and sort all columns in one place. After that you have to reorder all columns by calling grid.setColumnOrder.
Just so people know how I solved this issue, based on the comments:
When load data into Grid, first check database for columns of this Grid/user combination. If find such a column order, call setColumnOrder(userColumns).
Added 2 buttons to top, one to save column order, one to reset it.
"Save" button only enabled after moving at least one column.
"Reset" button only enabled if at least one column was moved. One column was moved either because of the DB, or because user JUST moved a column.
On save, save to DB. On reset, clear from DB, and reset Grid to original column order.
We chose not to save the column order each time they changed the order, directly in the addColumnReorderListener, because we realized sometimes users might move columns around temporarily, and one really want to save that column order for the future. That said, the saving inside the addColumnReorderListener worked well.
We don't currently need to save the column sizes, as suggested by #Simon Martinelli, but we are keeping it as an idea for the future. I fully expect it would work.
I have a TcxGrid component to show data of a MS Access table. One of this columns have a picture. The column "Properties" of this column is marked as "ButtonEdit".
I don't want to use a BlobEdit. I want to create another form, for display this picture. It will be opened by OnButtonClick() event of the grid column. But, I don't know how to get the column content (as TStream or other type), or the column name/field name in the OnButtonClick() event. I can't fix the column name, because it's a "generic" grid for show any Access table.
How can I do it?
It will be nice to understand your question better if you can post your code. But offcourse You can get column contents easily by using FieldByName method. Try to use that.
You did not say how you load the data into the grid, but to get the cell content you can use:
VarAsType(cxGrid1TableView1.DataController.Values[cxGrid1TableView1.Controller.FocusedRecordIndex,cxGrid1TableView1.Controller.FocusedColumnIndex],varString)
I am new to PowerBuilder and I need to add a new column to a DataObject. The DataObject has several fields which retrieves data using select statement. So if I add a column in the select statement I get another field with a name compute_0041 along with the added column field. When i try to remove the compute_0041 field I cannot see any value in the field representing a new column. How do I remove the compute_0041 that gets automatically added?
Thanks
In Datawindow if you accidentally put a 0 or '' in one of the rows in the tab called Computed Columns then these columns may come in. Of course, you can also have a computed column yourself by specifying it there but since it seems you think you didnt do anything and it came up on its own it appears to be an accidental issue.
You can of course check for it by going to the SQL mode and checking for it there. Also, the last tab in the design view it shows the complete generated SQL where you can easily see a select column that is not chosen by you.
Hope the above will aid you to identify the issue. Please let me know if you still have the issue.
A bit of History:
I have a DBlistbox containing textt descriptions and I store just the codes of this in a mysql table which is displayed in a dbgrid. User can select multiple options and I like to process these and store as comma separated values in one of the columns (this column is invisible in the dbgrid).
Right now I can populate the listbox when the user scroll through the dbgrid using event Afterscroll and Formcreate. But when I try to process the list and update the myquery behind the dbrgid I get an error saying 'Dataset not in Edit or Insert mode' - I do this in beforescroll
Please help!!
I have tried to set the dataset to edit mode before changing then as soon the data is posted dbgrid seems to have funny characters
If I got you right, the DBListBox is not connected to the dataset lonked in the grid? This would explain why the grid's dataset is not set to edit mode when you change the data in the DBListBox.
Anyway, whenever you change data that has to go into the mysql table, you should switch this dataset into edit mode. Then you can place your coding of the comma separated values into the OnBeforePost event.
When the dataset scrolls without any change in the data of the listbox, there is no need to store any data. This is achieved with the above approach as without edit mode no BeforePost event will fire in this case.
So I'm messing around with a new project in Delphi 2009 and the default components that can be dropped onto a form for accessing data consist of a SQLConnection, DataSource and SQLQuery. If I add a simple select to the query component, say:
select name from customers
and then drop a DBComboBox on the form and link it up with the DataSource I get a single record in the combo box. After using Google for half and hour to figure out what I was doing wrong it looks like you have to manually add some code to your project which loops through the dataset and adds all the records to the drop down box. Something like:
while not SQLQuery.eof do
begin
DBComboBox.items.add(SQLQuery.fieldbyname('name').asstring);
SQLQuery.next;
end;
And that actually sort of works, but then you get a list in the drop down which you can't actually select anything from. Regardless of the result though I'm wondering why would you even use a DBComboBox if you have to manually add the result of your query to it? Seems to me that if it doesn't automatically populate the db combo box with the result of the query then we might as well be using a non-data-aware component like tcombobox.
I guess what I'm asking is why does it work this way? Isn't the purpose of data aware drag-and-drop controls to minimize the amount of actual written code and speed development? Is there a method that I'm missing that is supposed to make this easier?
A TDBComboBox doesn't get its list of values from the database; it gets its current value from the database. Link it to a field in your dataset, and when you change the active record, the combo box's current value will change. Change the combo box's current value, and the corresponding field's value will change.
If you want to get the list of values from the database as well, then use a TDBLookupComboBox.
This is all covered in the help:
Using TDBListBox and TDBComboBox
Displaying and Editing Data in Lookup List and Combo Boxes
Defining a Lookup List Column
I think you want the TDBLookupComboBox because that allows you to lookup from a list of items where the list comes from a dataset.
In the TDBComboBox, the list is just a TStrings manually filled with data.
--jeroen
DbCombox is a dbaware version of the standard combobox component.