Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to find out which column what doubled clicked in a table viewer
How to find out which column what doubled clicked in a table viewer [message #443228] Wed, 22 September 2004 12:09 Go to next message
Richard Moore is currently offline Richard MooreFriend
Messages: 71
Registered: July 2009
Member
Hi All,

Anybody know how to find out which column was doubled clicked on from a
table viewer, the idea is the user double clicks on a column which has lots
of text in it and it's displayed in a pop up dialog box, this works because
I only had 1 long text colum, now I have two long text columns and I have
to find out which one the user double clicked on, to display the correct
data? Any ideas?

Cheers
Richard
Re: How to find out which column what doubled clicked in a table viewer [message #443314 is a reply to message #443228] Wed, 22 September 2004 13:01 Go to previous messageGo to next message
Paul Singleton is currently offline Paul SingletonFriend
Messages: 37
Registered: July 2009
Member
Richard Moore wrote:

> Anybody know how to find out which column was doubled clicked on from a
> table viewer, the idea is the user double clicks on a column which has lots
> of text in it and it's displayed in a pop up dialog box, this works because
> I only had 1 long text colum, now I have two long text columns and I have
> to find out which one the user double clicked on, to display the correct
> data? Any ideas?

I use these to identify the row and col index of a table cell
(not only double-click but also drag-and-drop):

// column no (0+) containing the table-relative ordinate x
private static int tableXToColNo(Table table, int x) {
int topIndex = table.getTopIndex(); // topmost visible row as good as any for this purpose (?)
int colCount = table.getColumnCount();
int colNo = -1; // unless we find otherwise
// ISSUE: (how) can we get col widths when there are no rows?
try {
TableItem row = table.getItem(topIndex);
for (int i = 0; i < colCount && colNo < 0; i++) {
Rectangle r = row.getBounds(i);
if (x < r.x + r.width) { // or width-1?
colNo = i; // this terminates the iteration
}
}
} catch (IllegalArgumentException e) {
// presumably no rows in the table (topIndex == -1) hence colNo = -1 (??)
}
return colNo;
}
// row no (0+) containing the table-relative ordinate y
private static int tableYToRowNo(Table table, int y) {
int topIndex = table.getTopIndex();
int itemCount = table.getItemCount();
int rowNo = -1; // unless we find otherwise
for (int i = topIndex; i < itemCount && rowNo < 0; i++) {
Rectangle r = table.getItem(i).getBounds(0); // col[0] is as good as any
if (y < r.y + r.height) { // or height-1?
rowNo = i; // this terminates the iteration
}
}
return rowNo; // -1 -> "y is not in a row" (i.e. beyond last row)
}

The blank "rows" below the last actual row return -1, as does the
space to the right of the last actual column, but if there are no
rows in the table then tableXToColNo() is no good.

There's a snippet which tackles this but it seems unnecessarily
combinatorial to me...

Paul Singleton
Re: How to find out which column what doubled clicked in a table viewer [message #443320 is a reply to message #443228] Wed, 22 September 2004 15:35 Go to previous message
Tiberiu Caprita is currently offline Tiberiu CapritaFriend
Messages: 68
Registered: July 2009
Member
Are you writing code for Windows?

If so, take a look on SWT Table Class, function
public TableItem getItem (Point point);

and do something similary using
final int LVM_SUBITEMHITTEST = OS.LVM_FIRST + 57; //from comctrl.h

with Point coordonates from MouseEvent (this code should run on Table
DblClickListener) fill LVHITTESTINFO
and call
OS.SendMessage (wTable.handle, LVM_SUBITEMHITTEST, 0, pInfo);
at the end in pInfo you have selected iIem (Row) and iSubItem (Column).

Other way, is to check the x obtained from MouseEvent in which TableColumn
is included...

Tiberiu
Previous Topic:word + SWT + applet problem
Next Topic:TableEditor misallignment when image present in table
Goto Forum:
  


Current Time: Fri Apr 19 22:07:29 GMT 2024

Powered by FUDForum. Page generated in 0.03232 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top