java - How to pass values of a selected row from tableviewer to a text box in SWT -
i have table has 10 rows, want is: when click button "modify" want pass selected table row values respective textboxes.
i tried codes, not full filling needs,
maintable.addlistener(swt.selection, new listener() { public void handleevent(event e) { string string = ""; tableitem[] selection = maintable.getselection(); (int = 0; < selection.length; i++) string += selection[i] + " "; final string appname=string.substring(11, string.length()-2); system.out.println(appname); } });
the above code printing selected row values in console, want set values textboxes.
how can this?
here example code:
private static int columns = 3; private static list<text> texts = new arraylist<>(); public static void main(string[] args) { display display = new display(); final shell shell = new shell(display); shell.settext("stackoverflow"); shell.setlayout(new gridlayout(columns, false)); table table = new table(shell, swt.full_selection); table.setlayoutdata(new griddata(swt.fill, swt.fill, true, true, columns, 1)); table.setheadervisible(true); /* create columns */ (int col = 0; col < columns; col++) { new tablecolumn(table, swt.none).settext("col " + col); } /* create cells */ (int row = 0; row < 10; row++) { tableitem item = new tableitem(table, swt.none); (int col = 0; col < table.getcolumncount(); col++) { item.settext(col, "cell " + row + " " + col); } } /* pack columns */ (int col = 0; col < table.getcolumncount(); col++) { table.getcolumn(col).pack(); } /* create text fields */ (int col = 0; col < columns; col++) { text text = new text(shell, swt.border); texts.add(text); } /* listen selection */ table.addlistener(swt.selection, new listener() { @override public void handleevent(event e) { table table = (table) e.widget; tableitem item = table.getitem(table.getselectionindex()); /* fill texts */ (int col = 0; col < table.getcolumncount(); col++) { texts.get(col).settext(item.gettext(col)); } } }); shell.pack(); shell.open(); while (!shell.isdisposed()) { if (!display.readanddispatch()) display.sleep(); } display.dispose(); }
looks this:
Comments
Post a Comment