Re: TableDataSet and PickList usage - you can actually run this classin your application


2005-03-10 09:43:13 PM
jbuilder15
Well, I figured out the reason for this. I was creating this window from
another JDialog window and I was not specifying an "owner" for
CreateTable_IF. Please disregard this entire item.
Thanks,
Anthony
Anthony Perera wrote:
Quote
I have been successful (thanks to this newsgroup) in using picklists
which rely on QueryDataSets. I am trying to use TableDataSets instead
for this particular window. I had a feeling it would not go smoothly so
I created this small test class. The main problem is that when I go to
edit the last column (which contains the picklist) in the grid it
doesn't drop open to show me what the possible values are. If I use my
keyboard to go "up" or "down" it allows me to choose a value. Please
give it a try and tell me what you think.



import javax.swing.*;
import java.awt.*;

public class CreateTable_IF extends JDialog {
BorderLayout borderLayout1 = new BorderLayout();
com.borland.dbswing.JdbTable table_columns = null;
com.borland.dx.dataset.TableDataSet tds_columns = null;

public CreateTable_IF() {
try {
jbInit();
this.setSize(500,600);
this.show();
}
catch(Exception ex) {
ex.printStackTrace();
}
}

void jbInit() throws Exception {
JPanel main_panel = new JPanel (new BorderLayout());
this.setContentPane(main_panel);
//create the grid
table_columns = new com.borland.dbswing.JdbTable();
//add columns to grid
com.borland.dx.dataset.TableDataSet tds_columns = new
com.borland.dx.dataset.TableDataSet();
//first column - column name
com.borland.dx.dataset.Column column_name = new
com.borland.dx.dataset.Column("name", "Name",
com.borland.dx.dataset.Variant.STRING );
column_name.setEditable(true);
//second column - type - this should be a drop down box
com.borland.dx.dataset.Column column_type = new
com.borland.dx.dataset.Column("type", "Type",
com.borland.dx.dataset.Variant.STRING );

//create the picklist dataset
com.borland.dx.dataset.TableDataSet tds_available_column_types = new
com.borland.dx.dataset.TableDataSet ();
com.borland.dx.dataset.Column column_available_types = new
com.borland.dx.dataset.Column("datatype", "Type",
com.borland.dx.dataset.Variant.STRING );
tds_available_column_types.addColumn(column_available_types);
tds_available_column_types.open();
tds_available_column_types.insertRow(true);
tds_available_column_types.setString("datatype", "VarChar");
tds_available_column_types.post();
tds_available_column_types.insertRow(true);
tds_available_column_types.setString("datatype", "Integer");
tds_available_column_types.post();
tds_available_column_types.insertRow(true);
tds_available_column_types.setString("datatype", "Float");
tds_available_column_types.post();
tds_available_column_types.insertRow(true);
tds_available_column_types.setString("datatype", "LongVarChar");
tds_available_column_types.post();
//construct the picklist descriptor and set it
com.borland.dx.dataset.PickListDescriptor pldesc = new
com.borland.dx.dataset.PickListDescriptor (tds_available_column_types,
new String[] {"datatype"},new String[] {"datatype"},new String[]
{"type"},false);
//add columns to dataset
tds_columns.setColumns(new com.borland.dx.dataset.Column[]
{column_name, column_type});
column_type.setPickList(pldesc);


//the grid to the center panel
tds_columns.open();
table_columns.setDataSet(tds_columns);
tds_columns.insertRow(true);
table_columns.setEditable(true);
tds_columns.setEditable(true);
main_panel.add(table_columns, BorderLayout.CENTER);
//create the navigator toolbar
com.borland.dbswing.JdbNavToolBar toolbar = new
com.borland.dbswing.JdbNavToolBar();
toolbar.setDataSet(tds_columns);
//add it to the SOUTH
main_panel.add(toolbar,BorderLayout.SOUTH);
}
}