craftleft.gif (3002 bytes)QuickTable
Home | API | Tutorial | Download | Support | Contact topblack.gif (108 bytes)


QuickTable User Cp  |  Register  |  Members  |  Search  |  Help
    |- QuickTable Discussion Forums > Events/Actions Post New Topic   Post A Reply
If row validation fails, do not allow to go to next row printer friendly version
next newest post | next oldest post
Author Messages
infow
Lieutenant General

Gender: Male
Location: France
Registered: Mar 2005
Status: Offline
Posts: 38

Click here to see the profile for infow Send email to infow Send private message to infow Find more posts by infow Edit or delete this message Reply w/Quote
Posted Friday, April 22, 2005 @ 09:54:07  

Hi,
i'm using beforeInsert (DatabaseChangeListener) to validate a new line.

How can i do to not going to another line until the function is returning TRUE ?

I'll try selectCell(row,...); but it's doing nothing !

Thank and have a nice day

--------------------
Olivier

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Tuesday, April 26, 2005 @ 21:53:15  

when user moves to a different row, before the actual row transfer takes place, beforeInsert method will be called. Since it is in transition from oldrow to new row the selectCell method is not working

You should not use beforeInsert to acheive this. You should really add a rowselectionlistener to the table and only if your row validation is successful you should allow the row change otherwise you should consume that event so that the row tranfer doesn't happen.

infow
Lieutenant General

Gender: Male
Location: France
Registered: Mar 2005
Status: Offline
Posts: 38

Click here to see the profile for infow Send email to infow Send private message to infow Find more posts by infow Edit or delete this message Reply w/Quote
Posted Monday, May 2, 2005 @ 06:53:22  

what do you mean wit rowselectionlisnter ?
Is this a mouseListener and how can i cosume the event ?
How can i know the row selected and the row from where the user is coming from ?
when i use mousListner, then it's only working for mouse events and not others (like button or key event to change row ...) ...
Could you give more eplication please ?
Thanks in adavance and have a nice day .

--------------------
Olivier

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Wednesday, May 4, 2005 @ 22:41:02  

Please have a look at the following discussion about how to listen for row selection change.
http://quicktable.org/discussion/cutecast/cutecast.pl?forum=12&thread=116

If you do not want to allow the row change, you can consume this event.

We will add a better way to handle these in future webtag releases.

infow
Lieutenant General

Gender: Male
Location: France
Registered: Mar 2005
Status: Offline
Posts: 38

Click here to see the profile for infow Send email to infow Send private message to infow Find more posts by infow Edit or delete this message Reply w/Quote
Posted Tuesday, July 26, 2005 @ 11:28:37  

hi,
i try to add a rowListner but i don't know how to stay in the line who have a problem.
Could you please tell me more how to do ?
Thank and have a nice day

i had this code to the tabel :

javax.swing.JTable table = getTable();
javax.swing.ListSelectionModel rowSM = getTable().getSelectionModel();

rowSM.addListSelectionListener(new javax.swing.event.ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
int currentSelectedRow = getTable().getSelectedRow();
if( currentSelectedRow == lastSelectedRow || currentSelectedRow == -1 )
return;
else
{
int indexColonne = getColumnByDatabaseName(ClientFactureLigneTableDef.cCodeArticle).getModelIndex() - 1;
int indexRow = lastSelectedRow;
String val = getValueAt(indexRow, indexColonne).toString();
if (getValueAt(indexRow, indexColonne) == null ||val.compareTo("")==0)
{
System.out.println("MyJTable test2 : " + currentSelectedRow + " " + lastSelectedRow);
// NEVER GO INTO THIS ONE AND THE VALUE IS NULL !
}
else
lastSelectedRow = currentSelectedRow;
}

// the currently selected row is currentSelectedRow,
// now you can use dBTable1.getValueAt() and get the data in different columns
// of this row

}

});

--------------------
Olivier

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Thursday, July 28, 2005 @ 08:41:51  

If you spend some time to study the event listeners and swing , you can easily write the code. I have given a quick implementation, to give you an idea, but you should polish this to make it work for you.

Code:

javax.swing.JTable table = dBTable1.getTable();
javax.swing.ListSelectionModel rowSM = table.getSelectionModel();
int lastSelectedRow = 0;

rowSM.addListSelectionListener(new javax.swing.event.ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
int currentSelectedRow = table.getSelectedRow();

if( currentSelectedRow == lastSelectedRow || currentSelectedRow == -1 )
return;

//this were you need to add the code to do the validation when user moves from one row to another

System.out.println("user moving from " + currentSelectedRow + " to " + lastSelectedRow);

//the row from which user is moving
int indexRow = lastSelectedRow;

//the column which we need to validate
int indexColonne = getColumnByDatabaseName(ClientFactureLigneTableDef.cCodeArticle).getModelIndex() - 1;

Object val = getValueAt(indexRow, indexColonne);

System.out.println( "row=" + indexRow + " checking column=" + indexColonne + " value=" + val);

if (val == null || val.toString().compareTo("")==0)
{

System.out.println( "value empty, so not allowing to go to next row");
//Important: consume the event, so that it doesn't move to next row
e.consume();

return;

}
else
{
System.out.println( "validation successfull");
}

//assign the last selected row to the current selected row, for future use
lastSelectedRow = currentSelectedRow;

}
});

infow
Lieutenant General

Gender: Male
Location: France
Registered: Mar 2005
Status: Offline
Posts: 38

Click here to see the profile for infow Send email to infow Send private message to infow Find more posts by infow Edit or delete this message Reply w/Quote
Posted Monday, August 1, 2005 @ 07:23:08  

Thank for your encouragement but i have take time to have a solution before asking you something.

Before my question to the support, i had add a rowlistner like you told me (in a previous support) but the consume method is not defined for this event listselectionevenent !
So i have had this line instead of consume :

stopEditing();
setRowSelectionInterval(row, row);
setColumnSelectionInterval(column, column);
scrollRectToVisible(getCellRect(row, column, true));
editCellAt(row, column);

but it's not a good code. THat's why i ask you an another solution.

Have a nice day

--------------------
Olivier

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Monday, August 1, 2005 @ 09:46:50  

We are planning to add a new method to do the row validation. Until then please use your current workaround.
Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Wednesday, November 23, 2005 @ 11:04:29  

A new class DBTableEventListener has been added which will help to stop the user from moving to a new row if the validation fails

boolean beforeRowSelectionChange(int fromRow, int toRow, int fromColumn, int toColumn)
boolean void afterRowSelectionChange(int fromRow, int toRow)

infow
Unregistered
Edit or delete this message Reply w/Quote
Posted Thursday, December 8, 2005 @ 11:16:42  

wondurfull ! ! !
Thank a lot. It's working !

have a nice day

Post New Topic   Post A Reply Jump to:
Contact Us | QuickTable - A Java DBGrid | Privacy Policy All times are GMT -5 Hours.
Welcome to QuickTable Forums, Guest!  
Login
Username :
Password :
In order to fully utilize the abilities of this board, you are required to register as a member. Registration is free, and allows you to do lots of things including turning on or off certain features of this board. Register now!
Powered by CuteCast v2.0 BETA 2
Copyright © 2001-2003 ArtsCore Studios