So in application I've created a search for name page where the user will enter there the name and as the user types ( Every time a key is pressed) an SQL statement is ran that will get the records like 'name%'.
This works fine but when it comes to putting the values into the table everytime the user presses a key it append the found results to the table instead of replace the values. Meaning everytime a key is pressed...duplicate rows are generated.
So I was wondering if anyone had a solution to stop the rows being duplicated and instead replaced with the new values? Im using a default table model:
private DefaultTableModel tModel = new DefaultTableModel(0, 0);
My code:
#Override
public void keyReleased(KeyEvent e) {
updateTable();
table.setModel(tModel);
formPanel.add(table);
tModel.fireTableDataChanged();
}
public void updateTable(){
System.out.println("Save member 1");
try{
//CHANGE THE VALUES SO WHEN CLICKS SAVE MEM
/*-------------------------------------*/
//Connection + Statement
conDB = getConnection();
stmt = conDB.createStatement();
String searchSql = "select * from members where name "
+ " LIKE '" + txtName.getText() +"%'";
if(!txtName.getText().equals(""))
{
r = stmt.executeQuery(searchSql);
}
System.out.println("searching");
tModel.setColumnIdentifiers(columnNames);
while(r.next()){
tModel.addRow(new Object[] {
r.getString("name")
});
}
}
catch(SQLException er){
System.out.println("Error was: " + er);
}
}
public searchBoth(){
super("Search");
this.setBounds(400, 500, 854,400);
this.setVisible(true);
mainCon.add(formPanel);
formPanel.add(lblName);
formPanel.add(txtName);
txtName.addActionListener(this);
addKeyListener(this);
txtName.addKeyListener(this);
}
set rowCount to 0 and add rows .this will remove existing rows and add new rows
tModel.setRowCount(0);
code
System.out.println("searching");
tModel.setRowCount(0);// *********************remove current rows to replace
tModel.setColumnIdentifiers(columnNames);
while(r.next()){
tModel.addRow(new Object[] {
r.getString("name")
});
}
Related
I have read a similar post but I still cannot get what is the problem.
I created a table in ms access, named DOCTOR, there are columns: DoctorID(number), Name(text), PhoneNumber(number), Department(text) and Specialization(text)
I connect the database to java through UCanAccess, below is the code to get connection
import java.sql.*;
public class Doctor
{
public static Connection connection; //sharing the memory
public static Connection connect() throws ClassNotFoundException, SQLException
{
String db = "net.ucanaccess.jdbc.UcanaccessDriver";
Class.forName(db);
String url = "jdbc:ucanaccess://C:/Users/user.oemuser/Documents/Doctor.accdb";
connection = DriverManager.getConnection(url);
return connection;
}
}
In my GUI class, i have a method called getConnect to show the data from database to textfield
public void getConnect()
{
try
{
connection = Doctor.connect();
statement=connection.createStatement();
String sql = "SELECT * FROM DOCTOR";
results = statement.executeQuery(sql);
results.next();
id = results.getInt("DoctorID");
name = results.getString("DoctorName");
phone = results.getInt("PhoneNumber");
dept = results.getString("Department");
spec = results.getString("Specialization");
textField1.setText("" +id);
textField2.setText(name);
textField3.setText("" +nf3.format(phone));
textField4.setText(dept);
textField5.setText(spec);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
and below is the code for the button1 which is the next button.
if(evt.getSource() == button1)
{
try
{
connection = Doctor.connect();
connection.setAutoCommit(false);
statement=connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
String sql1 = "SELECT * FROM DOCTOR";
results = statement.executeQuery(sql1);
if(results.next())
{
textField1.setText("" +results.getInt("DoctorID"));
textField2.setText(results.getString("DoctorName"));
textField3.setText("" +nf3.format(results.getInt("PhoneNumber")));
textField4.setText(results.getString("Department"));
textField5.setText(results.getString("Specialization"));
}
else
{
results.previous();
JOptionPane.showMessageDialog(null, "No more records");
}
connection.commit();
}
catch(Exception ex){
ex.printStackTrace();
}
}
Obviously the best component to use here is a JTable if you want to query all records within a particular database table or at the very least place the result set into an ArrayList mind you database tables can hold millions+ of records so memory consumption may be a concern. Now, I'm not saying that your specific table holds that much data (that's a lot of Doctors) but other tables might.
You can of course do what you're doing and display one record at a time but then you should really be querying your database for the same, one specific record at a time. You do this by modifying your SQL SELECT statement with the addition of the WHERE clause statement and playing off the ID for each database table record, something like this:
String sql = "SELECT * FROM DOCTOR WHERE DoctorID = " + number + ";";
But then again we need to keep in mind that, if the schema for your DoctorID field is set as Auto Indexed which of course allows the database to automatically place a incrementing numerical ID value into this field, the Index may not necessarily be in a uniform sequential order such as:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,.......
instead it could possibly be in this order:
1, 3, 4, 5, 6, 9, 10, 11, 16, 17,....
This sort of thing happens in MS Access Tables where a table record has been deleted. You would think that the ID slot that is deleted would be available to the next record added to the table and would therefore hold that removed ID value but that is not the case. The Auto Index Increment (autonumber) simply continues to supply increasing incremental values. There are of course ways to fix this sequencing mismatch but they are never a good idea and should truly be avoided since doing so can really mess up table relationships and other things within the database. Bottom line, before experimenting with your database always make a Backup of that database first.
So, to utilize a WHERE clause to play against valid record ID's we need to do something like this with our forward and reverse navigation buttons:
Your Forward (Next) Navigation Button:
if(evt.getSource() == nextButton) {
try {
connection = Doctor.connect();
connection.setAutoCommit(false);
number++;
long max = 0, min = 0;
ResultSet results;
Statement statement=connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
// Get the minimum DoctorID value within the DOCTOR table.
String sql0 = "SELECT MIN(DoctorID) AS LowestID from DOCTOR";
results = statement.executeQuery(sql0);
while (results.next()){ min = results.getLong("LowestID"); }
// Get the maximum DoctorID value within the DOCTOR table.
sql0 = "SELECT MAX(DoctorID) AS HighestID from DOCTOR";
results = statement.executeQuery(sql0);
while (results.next()){ max = results.getLong("HighestID"); }
if (max <= 0) {
JOptionPane.showMessageDialog(null, "No records found in Doctor Table.");
return;
}
if (number > min) { previousButton.setEnabled(true); }
if (number > max) {
nextButton.setEnabled(false);
JOptionPane.showMessageDialog(null, "No more records");
number--;
}
results = null;
while (results == null) {
String sql1 = "SELECT * FROM DOCTOR WHERE DoctorID = " + number + ";";
results = statement.executeQuery(sql1);
long id = 0;
// Fill The GUI Form Fields....
while (results.next()){
//id = results.getLong("DoctorID");
textField1.setText("" +results.getInt("DoctorID"));
textField2.setText(results.getString("DoctorName"));
textField3.setText("" + results.getString("PhoneNumber"));
textField4.setText(results.getString("Department"));
textField5.setText(results.getString("Specialization"));
connection.commit();
return;
}
// ----------------------------------------------------------
if (id != number) { results = null; number++; }
}
}
catch(Exception ex){ ex.printStackTrace(); }
}
Your Reverse (Previous) Navigation Button:
if(evt.getSource() == previousButton) {
try {
connection = Doctor.connect();
connection.setAutoCommit(false);
number--;
long max = 0, min = 0;
ResultSet results;
Statement statement=connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
// Get the minimum DoctorID value within the DOCTOR table.
String sql0 = "SELECT MIN(DoctorID) AS LowestID from DOCTOR";
results = statement.executeQuery(sql0);
while (results.next()){ min = results.getLong("LowestID"); }
// --------------------------------------------------------------------------
// Get the maximum DoctorID value within the DOCTOR table.
sql0 = "SELECT MAX(DoctorID) AS HighestID from DOCTOR";
results = statement.executeQuery(sql0);
while (results.next()){ max = results.getLong("HighestID"); }
// --------------------------------------------------------------------------
if (max <= 0) {
JOptionPane.showMessageDialog(null, "No records found in Doctor Table.");
return;
}
if (number < min) {
previousButton.setEnabled(false);
JOptionPane.showMessageDialog(null, "No more records");
number++;
}
if (number < max) { nextButton.setEnabled(true); }
results = null;
while (results == null) {
String sql1 = "SELECT * FROM DOCTOR WHERE DoctorID = " + number + ";";
results = statement.executeQuery(sql1);
long id = 0;
// Fill The GUI Form Fields....
while (results.next()){
textField1.setText("" +results.getInt("DoctorID"));
textField2.setText(results.getString("DoctorName"));
textField3.setText("" + results.getString("PhoneNumber"));
textField4.setText(results.getString("Department"));
textField5.setText(results.getString("Specialization"));
connection.commit();
return;
}
// ----------------------------------------------------------
if (id != number) { results = null; number--; }
}
}
catch(Exception ex){ ex.printStackTrace(); }
}
Things To DO...
So as to remove duplicate code, create a method named
getMinID() that returns a Long Integer data type. Allow this method to accept two String Arguments (fieldName and
tableName). Work the above code section used to gather the minimum DoctorID value within the DOCTOR table into the new
**getMinID() method. Use this new method to replace the formentioned code for both the Forward (Next) and Revese (Previous)
buttons.
So as to remove duplicate code, create a method named
getMaxID() that returns a Long Integer data type. Allow this method to accept two String Arguments (fieldName and
tableName). Work the above code section used to gather the maximum DoctorID value within the DOCTOR table into the new
getMaxID() method. Use this new method to replace the formentioned code for both the Forward (Next) and Revese (Previous)
buttons.
So as to remove duplicate code, create a void method named
fillFormFields(). Allow this method to accept two arguments, one as Connection (*connection) and another as ResultSet
(results) . Work the above code section used to Fill The GUI
Form Fields into the new fillFormFields() method. Use this new
method to replace the formentioned code for both the Forward (Next)
and Revese (Previous) buttons.
Things To Read That Might Be Helpful:
The SQL WHERE clause statement and the SQL ORDER BY statement for sorting your result set.
Searching For Records
What i'm trying do here is that when i select a row in my table , after loading data , it should display the selected row's value in a text field (selectedRowTF). But as soon as i click on the jButton the following error generates -
java.lang.ArrayIndexOutOfBoundsException: -1
Since the error occurs even before the data is loaded , it leaves no chance for me to even select a row.
Also do you think I'm using the correct code to get the row's value?
Stack Trace
DefaultTableModel model;
model=(DefaultTableModel)tbl.getModel();
try {
Class.forName("java.sql.Driver");
Connection con= DriverManager.getConnection("jdbc:mysql://localhost:3306/divign","root","password");
Statement stmt=con.createStatement();
int row=tbl.getSelectedRow();
String rowSelected=(tbl.getModel().getValueAt(row, 0).toString());
String query="SELECT * FROM CUSTOMER WHERE CUSTOMER_ID = '"+customerIdTF.getText()+"' ;";
ResultSet rs=stmt.executeQuery(query);
if(rs.next()) {
model.addRow (new Object[ ] {
rs.getInt(1),rs.getString(2),rs.getString(3)
});
selectedRowTF.setText(""+rowSelected);
}
rs.close();
stmt.close();
con.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(null,e.toString());
}
If you just load your data, the tbl.getSelectedRow() returns -1.
After that you try to get the string value of the first column of your invalid row.
String rowSelected=(tbl.getModel().getValueAt(row, 0).toString());
=> that getValueAt leads to your exception.
Try the following:
String rowSelected = "";
if(row != -1)
{
rowSelected = tbl.getModel().getValueAt(row, 0).toString();
}
EDIT
As you said you just want to get the selected value, the position of your code is wrong.
You are trying to get the value of the selected row at the time you are loading your data. But at that time you don't select a row.
I think you need something like that (Value is printed out on a mouse click at the table):
tbl.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
int row = table.getSelectedRow();
if (row > -1) {
String value = (table.getModel().getValueAt(row, 0).toString());
System.out.println("Value of row " + row + " col 0: '" + value + "'");
selectedRowTF.setText(value);
} else {
System.out.println("Invalid selection");
}
}
});
Or you can react on the selection with a button click:
private void btClickActionPerformed(java.awt.event.ActionEvent evt) {
int row = table.getSelectedRow();
if (row > -1) {
String value = (table.getModel().getValueAt(row, 0).toString());
System.out.println("Value of row " + row + " col 0: '" + value + "'");
selectedRowTF.setText(value);
} else {
System.out.println("Invalid selection");
}
}
Your situation is that when you called tbl.getSelectedRow(), it returned -1. That is a sentinel value to indicate that no row is selected. A row is selected when the mouse clicks on it, or when the keyboard moves the selection to it. You will need to handle the situation when no row is selected. I don't know your requirements and goals, so I can't advise on how to do that. You can register a selection listener with the JTable if you want to be notified when the selection changes and react to it. (See getSelectionModel, addListSelectionListener, and ListSelectionListener)
You may get away without handling it if you didn't enable sorting or filtering on your JTable, however it is worth knowing that the row indexes in the view (JTable) are not the same indexes in the model (DefaultTableModel). Use the convertRowIndexToModel method to convert from the view's index (as reported by getSelectedRow()) to the model's index (required by getValueAt()).
The code you posted also contains SQL Injection issues. I recommend researching that topic, and fix it using a PreparedStatement and setString().
Here is a try block which serves the purpose of filtering through table_job to find rows which match keyword. However, when the table model changes, I am struggling to obtain the correct row index. It always picks the the first row, even though the filtered result shows a row which is not first.
I understand you can do something with fireTableDataChanged(), but I am not sure HOW and WHERE to do this, in the try and catch block OR in the setLabelText() method which displays the content of the table as . JLabel
try
{
sql = "SELECT Job.jobID as 'Job ID', Employer.name as'Company', Job.title as 'Role', Job.description as 'Description', Job.type as 'Type', Job.benefits as 'Benefits', Job.closing as 'Closing Date' FROM Job INNER JOIN Employer ON Job.employerID=Employer.employerID ORDER BY Employer.name";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
TableModel model = DbUtils.resultSetToTableModel(rs);
table_job.setModel(model);
final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
table_job.setRowSorter(sorter);
searchJob.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String text = keyword.getText();
if (text.length() == 0)
{
sorter.setRowFilter(null);
}
else
{
sorter.setRowFilter(RowFilter.regexFilter(text));
}
}
});
}
catch (Exception e)
{
e.printStackTrace();
}
private void setLabelText()
{
try
{
String table_click0 = (table_job.getModel().getValueAt(
row, 0).toString());
String sqlSt = "SELECT Employer.name, * FROM Job INNER JOIN Employer ON Job.employerID = Employer.employerID WHERE jobID='"+table_click0+"' ";
//rest of code to Label text...
}
The String table_click0 = (table_job.getModel().getValueAt(row, 0).toString()); is picking up the wrong row, not the updated selected row. How can I take this into account?
You probably need to convert your "row" value to a model index value (if your row value is retrieved from a "view" point of view), using convertRowIndexToModel. So just replace
String table_click0 = (table_job.getModel().getValueAt(row, 0).toString());
with
String table_click0 = table_job.getModel().getValueAt(table_job.
convertRowIndexToModel(row), 0).toString());
Quick fix: how to get the actual row in a filtered list
int row=getjTable().getSelectedRow();
if (getjTable().getRowSorter()!=null) {
row = getjTable().getRowSorter().convertRowIndexToModel(row);
}
I have a MySQL database which contains data i would like to populate into a JList in my java program. I have two JList, one which is fill with Events Title and the second is to be fill with Guest Name.
What i would like is when the user click on any of the Events Title, the second JList will show all the Guest Name that belong to that Event.
I have already successfully populate the first JList with all the Events Title. What I'm having trouble with is when the user click on the Events Title, the Guests Name will show twice on the second JList. How can i make it to show only once?
Here is what i got so far...
Java Class
private JList getJListEvents() {
if (jListEvents == null) {
jListEvents = new JList();
Border border = BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(1, Color.black, Color.black), "Events", TitledBorder.LEFT, TitledBorder.TOP);
jListEvents.setBorder(border);
jListEvents.setModel(new DefaultListModel());
jListEvents.setBounds(new Rectangle(15, 60, 361, 421));
Events lEvents = new Events();
lEvents.loadEvents(jListEvents);
jListEvents.addListSelectionListener(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent e){
EventC eventC = new EventC();
//eventC.MonitorRegDetailsInfo(jListEvents, jTextFieldEventName, jTextFieldEventVenue, jTextFieldEventDate, jTextFieldEventTime, jTextAreaEventDesc);
//eventC.MonitorRegPackageInfo(jListEvents, jTextFieldBallroom, jTextFieldBallroomPrice, jTextFieldMeal, jTextFieldMealPrice, jTextFieldEntertainment, jTextFieldEntertainmentPrice);
eventC.MonitorRegGuest(jListEvents, jListGuest);
}
});
}
return jListEvents;
}
Controller Class
public void MonitorRegGuest(JList l, JList l2){
String event = l.getSelectedValue().toString();
Events retrieveGuest = new Events(event);
retrieveGuest.loadGuests(l2);
}
Class with all the sql statement
public void loadGuests(JList l){
ResultSet rs = null;
ResultSet rs2 = null;
ResultSet rs3 = null;
MySQLController db = new MySQLController();
db.getConnection();
String sqlQuery = "SELECT MemberID FROM event WHERE EventName = '" + EventName + "'";
try {
rs = db.readRequest(sqlQuery);
while(rs.next()){
MemberID = rs.getString("MemberID");
}
} catch (SQLException e) {
e.printStackTrace();
}
String sqlQuery2 = "SELECT GuestListID FROM guestlist WHERE MemberID = '" + MemberID + "'";
try {
rs2 = db.readRequest(sqlQuery2);
while(rs2.next()){
GuestListID = rs2.getString("GuestListID");
}
} catch (SQLException e) {
e.printStackTrace();
}
String sqlQuery3 = "SELECT Name FROM guestcontact WHERE GuestListID = '" + GuestListID + "'";
try {
rs3 = db.readRequest(sqlQuery3);
while(rs3.next()){
((DefaultListModel)l.getModel()).addElement(rs3.getString("Name"));
}
} catch (SQLException e) {
e.printStackTrace();
}
db.terminate();
}
Thanks in advance!
Please for the time being forget about the SQL. Then follow the steps below:
Start with the example --- the corresponding Java Web Start link.
Play with the sample, to see how to add elements to a list.
Then all you need to do is grab a reference to the one you want to copy and for each element copy it then add to the 2nd list.
Enjoy Java.
EDIT:
I am still looking at your code and I am still confused of what is going on (Please consider making a SSCCE). But let me guess, as something is telling me that when you are calling the ListSelectionListener you are not using getIsValueAdjusting() of the ListSelectionEvent, right? Therefore, this might be as well it, for more read here.
As far as I can see, you aren't clearing the list before populate it, you could try to clear the model first, like:
String sqlQuery3 = "SELECT Name FROM guestcontact WHERE GuestListID = '" + GuestListID + "'";
try {
rs3 = db.readRequest(sqlQuery3);
DefaultListModel lm = (DefaultListModel)l;
lm.clear();
while(rs3.next()){
(lm.getModel()).addElement(rs3.getString("Name"));
}
} catch (SQLException e) {
e.printStackTrace();
}
I'm creating a bank application where I can use the search text field to find customers in the database(I'm using MySQL database). When I type in a letter to search a customer by its last name, the application does fetches the data from the database and shows the results in a JList. In my case, I have a total of 5 records in my database, which 4 last names starts with the letter "S" and one starts with the letter "M". Once the rows or results are in the JList, I can click on one row and automatically fills the first name, last name, city, and etc text filds with the proper information. However, there are two issues that I'm having:
In my case, if I search a last name by the letter "S," my JList will show only 4 records from the database, which is correct. When I select one row from the JList, it should automatically fills all the text fields with the proper information. However, if I select the first row in the JList, my text fields will always fill with the information with the last row in the JList. It doesn't matter which row I select in the JList, the text fields will alway fills the information with the last row.
If I search the letter "S", I get 4 records, which is correct. However, when the application is still running, and I decided to search the letter "M," I get one record, which is also correct, but if I try to search the letter "S" again, I get only one record. Why? It should be 4.
This what I'm trying to accomplish:
Bank Application link
Here is part of my code:
// function that will search for records in the database
private void searchRecord(){
try {
connect = DriverManager.getConnection(url,user,password);
SQLStatement = connect.createStatement();
Class.forName("com.mysql.jdbc.Driver");
model.clear();
String select = "SELECT * FROM customerinfo WHERE LastName LIKE '"+ txtSearch.getText().trim() +"%'";
rows = SQLStatement.executeQuery(select);
while(rows.next()){
//model.addElement(rows.getString("LastName"));
model.addElement(rows.getString("LastName") + ", " + rows.getString("FirstName") + " " + rows.getString("MiddleInitial") + ".");
}
rows.close();
SQLStatement.close();
connect.close();
} catch (ClassNotFoundException e) {
JOptionPane.showMessageDialog(this, "Where is your Mysql JDBC Driver?");
e.printStackTrace();
} catch (SQLException e){
JOptionPane.showMessageDialog(this, "SQLException: " + e.getMessage());
JOptionPane.showMessageDialog(this, "VendorError: " + e.getErrorCode());
}
}
// Implement Action Listener
private class handler implements ActionListener{
#Override
public void actionPerformed(ActionEvent event) {
// if user clicks on New Customer Button, do the following...
if(event.getSource() == newCustomer){
checkForEmptyFields();
insertDatabase();
clearFields();
} else if(event.getSource() == update){
checkForEmptyFields();
updateDatabase();
clearFields();
} else if(event.getSource() == remove){
checkForEmptyFields();
deleteRecord();
clearFields();
} else if(event.getSource() == cancel){
clearFields();
} else if(event.getSource() == open){
} else if(event.getSource() == search){
searchRecord();
}
}
}
// function that will set the text fields
private void setTextFields(int customerID, String firstName, String lastName, String middleInitial, String street, String city, String state, int zipCode, int phone, String email){
String convertCustomerID = Integer.toString(customerID);
txtCustomerID.setText(convertCustomerID);
txtFirstName.setText(firstName);
txtLastName.setText(lastName);
txtMiddleInitial.setText(middleInitial);
txtStreet.setText(street);
txtCity.setText(city);
txtState.setText(state);
String convertZipCode = Integer.toString(zipCode);
txtZip.setText(convertZipCode);
String convertPhone = Integer.toString(phone);
txtPhone.setText(convertPhone);
txtEmail.setText(email);
}
// Implement List Selection Listener
private class listener implements ListSelectionListener{
#Override
public void valueChanged(ListSelectionEvent event) {
try {
connect = DriverManager.getConnection(url,user,password);
SQLStatement = connect.createStatement();
String select = "SELECT * FROM customerinfo WHERE LastName LIKE '"+ txtSearch.getText().trim() + "%'";
rows = SQLStatement.executeQuery(select);
if(!event.getValueIsAdjusting()){
while(rows.next()){
setTextFields(rows.getInt("CustomerID"), rows.getString("FirstName"), rows.getString("LastName"), rows.getString("MiddleInitial"),
rows.getString("Street"), rows.getString("City"), rows.getString("State"), rows.getInt("ZipCode"), rows.getInt("Phone"),
rows.getString("Email"));
}
}
} catch(Exception ex) {
JOptionPane.showMessageDialog(null, "Cannot get field values");
}
}
}
It has to be the rows.next() that's giving me issue number 1. The rows.next() goes through all the records in the database, and after it is done going through all the records, it seems it stays at the last record. Somehow, I need to reset the position, and when I click on a row in the JList, it should be equal to the row that has the same values and fill all the text fields with the proper information.
I have tried everything, and at this point I have given up! Please help me! Thank you!
Your SELECT statement in the valueChanged method is going to select everything again. You will need to make it select only the record that you want. So you will need to have a means to identify the row you want in your list (like customer number or something) and then use that in the SELECT statement when responding to the selection event to get only the single customer.