Board index » jbuilder » How to fill a jComboBox with data from a QueryDataSet

How to fill a jComboBox with data from a QueryDataSet


2003-09-19 05:52:34 PM
jbuilder20
Hi all,
I am a complete newbie to JBuilder and Java (I'm used to Delphi :o).
Can you help me with a code sample on how to fill a jComboBox with data from
a column (named "NAME_LANG") in a queryDataSet when the window opens. ?
I have the query up an running and I can see the dataset in a grid.
Thanks in advance
/Claus
 
 

Re:How to fill a jComboBox with data from a QueryDataSet

//=========================================================================
//Execute the query to fill a jdbComboBox with data
//Param: combo ->the name of the JdbComboBox
//Param: addPercentSymbol ->0=no; 1=at the top; 2=at the end
//Param: querySQL ->the query to get the data from the database
//=========================================================================
void fillComboBox(JdbComboBox combo, int addPercentSymbol, String querySQL)
{
try
{
//Get actual selected index of the combobox
int comboIndex = combo.getSelectedIndex(); //get selected index
//Remove all items of the combobox
combo.removeAllItems();
System.out.println(querySQL);
TempDataSet.close();
TempDataSet.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(
db, querySQL, null, true, Load.ALL));
TempDataSet.executeQuery();
//Check if we have to add a percentsymbol(%) at the top of the list
if(addPercentSymbol == 1)
{
combo.addItem("%");
}
//Loop to fill the ComboBox with data
for(int i=0 ; i<TempDataSet.getRowCount() ; i++ )
{
TempDataSet.goToRow(i);
String item = TempDataSet.getString(0); //get value from column 1
combo.addItem(item);
}
//Check if we have to add a percentsymbol(%) at the end of the list
if(addPercentSymbol == 2)
{
combo.addItem("%");
}
//Check previous index, and set it (if available)
if(comboIndex>= 0)
{
combo.setSelectedIndex(comboIndex); //show previous selected item
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(this,ex.getMessage(), res.getString("errorMessageTitle"),0);
}
}
"ctb" < XXXX@XXXXX.COM >wrote:
Quote
Hi all,

I am a complete newbie to JBuilder and Java (I'm used to Delphi :o).

Can you help me with a code sample on how to fill a jComboBox with data from
a column (named "NAME_LANG") in a queryDataSet when the window opens. ?
I have the query up an running and I can see the dataset in a grid.

Thanks in advance

/Claus