Combo box in a table column
I have dragged and dropped one of my view objects as a table on a JClient form. Is there a way I can show one of the columns as a combo box?
Milos
URGENT!!!!!!!! Using a topic title like "URGENT" followed by exclamations is one sure way to not get an answer from people on the forum.
This is urgent... Not for us it isn't. Implying that your question is any more important than any other question on the forum is another way to not get a response.
Anyway your question is like big run on sentence and I have no idea what you are asking or what your problem is or what your code looks like.
If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.
Similar Messages
-
Problem in showing combo box in the table
Hello guys i just add up the combo box in the table but the problem is when i change the line in the table the combo disappear. i want it to be visible even if it is not in the selected row. i want that user can see the combo box in the table without clicking on it.
Please help;http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
Look in the page bottom ! -
Problem with combo box in a Matrix column
hi every one, i have a user form with a matrix(uid = 37) with some columns and one column is combo box. in that combo box i have to get values from OSTC table (Code)...i have written this code ..i dont know how to access the combo box so that i can get values to combo box when i execute the prg....
oitem = oForm.Items.Item("37") 37 is uid of omatrix2
oMatrix2 = oitem.Specific
oColumns = oMatrix2.Columns
oForm.DataSources.UserDataSources.Add("CSR1", SAPbouiCOM.BoDataType.dt_SHORT_TEXT, 1)
oColumn = oColumns.Item("V_6") ''for accessing the combo box item [V_6 is col uid ]
oCombo = oColumn.Cells.Item(omatrix2.row).Specific ''''''''problem line
oCombo.DataBind.SetBound(True, "", "CSR1")
rset = oDICompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
query = "select Code from OSTC"
rset.DoQuery(query)
Dim tc As String
rset.MoveFirst()
For row = 0 To rset.RecordCount - 1
tc = rset.Fields.Item("Code").Value
oCombo.ValidValues.Add(tc, row)
rset.MoveNext()
Next
oMatrix2.Columns.Item("V_6").DataBind.SetBound(True, "@SALE_CHILD", "U_Tax")Call objMain.objUtilities.LoadComboValuesForMatrix(FormUID, "27", "SELECT Code,Name FROM OSTC Order by Code", "V_19", objMatrix.RowCount)
Public Sub LoadComboValuesForMatrix(ByVal FormUID As String, ByVal ItemUID As String, ByVal strQuery As String, ByVal MtrxColId As String, ByVal Rowcount As Integer)
Dim inti As Integer
objRecSet = objMain.objUtilities.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
Try
Dim objmatrix As SAPbouiCOM.Matrix
Dim objCombo As SAPbouiCOM.ComboBox
objForm = objMain.objApplication.Forms.Item(FormUID)
objItem = objForm.Items.Item(ItemUID)
objmatrix = objItem.Specific
objCombo = objmatrix.Columns.Item(MtrxColId).Cells.Item(Rowcount).Specific
objItem.DisplayDesc = True
objRecSet.DoQuery(strQuery)
If objRecSet.RecordCount > 0 Then
If (objCombo.ValidValues.Count > 0) Then
For inti = 0 To objRecSet.RecordCount - 1
objRecSet.MoveNext()
Next
End If
If (objCombo.ValidValues.Count <= 0) Then
objCombo.ValidValues.Add("", "")
For inti = 0 To objRecSet.RecordCount - 1
objCombo.ValidValues.Add(Convert.ToString(objRecSet.Fields.Item(0).Value), Convert.ToString(objRecSet.Fields.Item(1).Value))
objRecSet.MoveNext()
Next
End If
End If
Catch ex As Exception
Throw ex
Finally
System.Runtime.InteropServices.Marshal.ReleaseComObject(objRecSet)
GC.WaitForPendingFinalizers()
GC.Collect()
End Try
End Sub -
Linking combo boxes to a table
I have made a set of combo boxes that allow the user to input a home and away football team and their scores. I have also setup a table with 4 teams in it. How can i link the combo boxes so that EG:
If Arsenal 2 - 1 Chelsea is a result inputted how can i link it to a table so that Arsenal will go top with 3 points, 2 goal for, 1 against etc
Basically i need to update the table from the info supplied by the combo boxes???we don't tolerate that attitude either....
besides I gave u guidelines, check the other thread, but u can be sure that nobody will help you if u keep this attitude...
READ the links I posted in that other thread, work on the issue then come back with questions and post your code so that we know how to help you based on your code..that's how it works here.. -
1. i have one html page - in that two combo boxes are there
2. first one called--> Bank Name and second one called-->Main Branch
3. i have a database table like BANK_MASTER(MAIN_BRANCH,BANK_NAME)
i am giving here some data for the above table:
(sbi-kurnool, sbi),(sbi-cadapah,sbi),(sbi-chittor,sbi),(ab-rangareddy,ab),(ab-varangal,ab) ..like that every bank has its own main branch in different location.
MY PROBLEM:
In HTML page, in the first combo box ie., Bank Name will display all the bank name using the table BANK_MASTER ie.,sbi,ab,cb,sbh ...... (its ok - i too get )
main Problem: Whenever i select a particular bank name in the first combo box, the second combo box ie.,Main Branch has to display the main branches using the table Bank_Master depending on the Selected bank name from the Bank Name Combo box ( ie., if we select the sbi, it has to display all main branches of sbi's only, but not other bank's main branches)Hi friend,
I had a similar situation and i tried to solve it by using XmlHttpRequest Object(used in AJAX).
U can checkout the below example just for further reference delete
UserForm.jsp:
==========
<head>
<script>
var xmlHttp
function showState(str)
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
alert ("Browser does not support HTTP Request")
return
var url="getState.jsp"
url=url+"?count="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChange
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
function stateChange()
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById("state").innerHTML=xmlHttp.responseText
</head>
<body>
<select name='country' onchange="showState(this.value)">
<option value='india>india</option>
</select>
<br>
<div id='state'>
<select name='state' >
<option value='-1'>pickone</option>
</select>
</div>
</body>
getState.jsp
============
<%@page language="java" import ="java.util.Hashtable" import ="java.util.Set" %>
<%
String country=request.getParameter("count");
response.setContentType("text/html");
response.setHeader("Cache-Control","no-cache");
try{
Hashtable ht = (Hashtable)session.getAttribute("<ATTRIBUTE_NAME>");
String buffer="<select name='state'><option value='-1'>Pick One</option>";
Set s=ht.keySet();
Object keys[]=s.toArray();
int size=keys.length;
for(int i=0; i < size;i++){
buffer=buffer+"<option value='"+ht.get(keys).toString()+"'>"+ht.get(keys).toString()+"</option>";
buffer=buffer+"</select>";
response.getWriter().println(buffer);
catch(Exception exp){
response.getWriter().println(exp);
%> I think u may go upon replacing country with your Main Branch and vice versa -
Link Combo box(drop down) to Column chart
Hello Gurus,
I am new to this Xcelsius world... I have 3 excel books with three different weeks data, i would like to create drop down for thr three week and link to the column bar chart with filter.
could you please help me any one.
thanks in adavance
MuvvaHi Anil,
I am trying to display the data in the spread sheet using the web services. I am able to get the web service as a query in xcelsius and i am trying to insert into excel and then i would to display in the spreadsheet table. I am unable to see the data in the excel and the spreadsheet action block.
Muvva -
Add combo box into table pagination
I want to add combo box into JavaFX table with pagination. Something like that:
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Pagination;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Callback;
public class MainApp extends Application
final ObservableList<Person> data = FXCollections.observableArrayList(
new Person("1", "Joe", "Pesci"),
new Person("2", "Audrey", "Hepburn"),
new Person("3", "Gregory", "Peck")
private Pagination pagination;
public static void main(String[] args) throws Exception
launch(args);
public int itemsPerPage()
return 1;
public int rowsPerPage()
return 5;
public VBox createPage(int pageIndex)
int lastIndex = 0;
int displace = data.size() % rowsPerPage();
if (displace > 0)
lastIndex = data.size() / rowsPerPage();
else
lastIndex = data.size() / rowsPerPage() - 1;
VBox box = new VBox(5);
int page = pageIndex * itemsPerPage();
for (int i = page; i < page + itemsPerPage(); i++)
TableView<Person> table = new TableView<>();
TableColumn numCol = new TableColumn("ID");
numCol.setCellValueFactory(
new PropertyValueFactory<Person, String>("num"));
numCol.setMinWidth(20);
TableColumn firstNameCol = new TableColumn("First Name");
firstNameCol.setCellValueFactory(
new PropertyValueFactory<Person, String>("firstName"));
firstNameCol.setMinWidth(160);
TableColumn lastNameCol = new TableColumn("Last Name");
lastNameCol.setCellValueFactory(
new PropertyValueFactory<Person, String>("lastName"));
lastNameCol.setMinWidth(160);
table.getColumns().addAll(numCol, firstNameCol, lastNameCol);
if (lastIndex == pageIndex)
table.setItems(FXCollections.observableArrayList(data.subList(pageIndex * rowsPerPage(), pageIndex * rowsPerPage() + displace)));
else
table.setItems(FXCollections.observableArrayList(data.subList(pageIndex * rowsPerPage(), pageIndex * rowsPerPage() + rowsPerPage())));
box.getChildren().add(table);
return box;
@Override
public void start(final Stage stage) throws Exception
pagination = new Pagination((data.size() / rowsPerPage() + 1), 0);
// pagination = new Pagination(20 , 0);
//pagination.setStyle("-fx-border-color:red;");
pagination.setPageFactory(new Callback<Integer, Node>()
@Override
public Node call(Integer pageIndex)
if (pageIndex > data.size() / rowsPerPage() + 1)
return null;
else
return createPage(pageIndex);
public static class Person
private final SimpleStringProperty num;
private final SimpleStringProperty firstName;
private final SimpleStringProperty lastName;
private Person(String id, String fName, String lName)
this.firstName = new SimpleStringProperty(fName);
this.lastName = new SimpleStringProperty(lName);
this.num = new SimpleStringProperty(id);
public String getFirstName()
return firstName.get();
public void setFirstName(String fName)
firstName.set(fName);
public String getLastName()
return lastName.get();
public void setLastName(String fName)
lastName.set(fName);
public String getNum()
return num.get();
public void setNum(String id)
num.set(id);
I suppose that this can be done with StackPane but I need some other more universal way to do this because I want to expand the table size. I need to place there the combo box always in a fix position.
Ref http://stackoverflow.com/questions/21147261/add-combo-box-into-table-paginationHi. You can do it using an AnchorPane:
AnchorPane.setBottomAnchor(comboBox, 40.0);
AnchorPane.setLeftAnchor(comboBox, 12.0);
The complete example :
import java.util.List;
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ListChangeListener.Change;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.Pagination;
import javafx.scene.Node;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextArea;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Callback;
public class TablePager extends Application {
final ObservableList<Person> data = FXCollections.observableArrayList(
new Person("1", "Joe", "Pesci"),
new Person("2", "Audrey", "Hepburn"),
new Person("3", "Gregory", "Peck"),
new Person("4", "Cary", "Grant"),
new Person("5", "De", "Niro"),
new Person("6", "Katharine", "Hepburn"),
new Person("7", "Jack", "Nicholson"),
new Person("8", "Morgan", "Freeman"),
new Person("9", "Elizabeth", "Taylor"),
new Person("10", "Marcello", "Mastroianni"),
new Person("11", "Innokenty", "Smoktunovsky"),
new Person("12", "Sophia", "Loren"),
new Person("13", "Alexander", "Kalyagin"),
new Person("14", "Peter", "OToole"),
new Person("15", "Gene", "Wilder"),
new Person("16", "Evgeny", "Evstegneev"),
new Person("17", "Michael", "Caine"),
new Person("18", "Jean-Paul", "Belmondo"),
new Person("19", " Julia", "Roberts"),
new Person("20", "James", "Stewart"),
new Person("21", "Sandra", "Bullock"),
new Person("22", "Paul", "Newman"),
new Person("23", "Oleg", "Tabakov"),
new Person("24", "Mary", "Steenburgen"),
new Person("25", "Jackie", "Chan"),
new Person("26", "Rodney", "Dangerfield"),
new Person("27", "Betty", "White"),
new Person("28", "Eddie", "Murphy"),
new Person("29", "Amitabh", "Bachchan"),
new Person("30", "Nicole", "Kidman"),
new Person("31", "Adriano", "Celentano"),
new Person("32", "Rhonda", " Fleming's"),
new Person("32", "Humphrey", "Bogart"));
private Pagination pagination;
public static void main(String[] args) throws Exception {
launch(args);
public int itemsPerPage() {
return 1;
public int rowsPerPage() {
return 5;
public VBox createPage(int pageIndex) {
int lastIndex = 0;
int displace = data.size() % rowsPerPage();
if (displace > 0) {
lastIndex = data.size() / rowsPerPage();
} else {
lastIndex = data.size() / rowsPerPage() - 1;
VBox box = new VBox();
int page = pageIndex * itemsPerPage();
for (int i = page; i < page + itemsPerPage(); i++) {
TableView<Person> table = new TableView<Person>();
TableColumn numCol = new TableColumn("ID");
numCol.setCellValueFactory(
new PropertyValueFactory<Person, String>("num"));
numCol.setMinWidth(20);
TableColumn firstNameCol = new TableColumn("First Name");
firstNameCol.setCellValueFactory(
new PropertyValueFactory<Person, String>("firstName"));
firstNameCol.setMinWidth(160);
TableColumn lastNameCol = new TableColumn("Last Name");
lastNameCol.setCellValueFactory(
new PropertyValueFactory<Person, String>("lastName"));
lastNameCol.setMinWidth(160);
table.getColumns().addAll(numCol, firstNameCol, lastNameCol);
if (lastIndex == pageIndex) {
table.setItems(FXCollections.observableArrayList(data.subList(pageIndex * rowsPerPage(), pageIndex * rowsPerPage() + displace)));
} else {
table.setItems(FXCollections.observableArrayList(data.subList(pageIndex * rowsPerPage(), pageIndex * rowsPerPage() + rowsPerPage())));
box.getChildren().addAll(table);
return box;
@Override
public void start(final Stage stage) throws Exception {
ObservableList<String> options =
FXCollections.observableArrayList(
"Opt1",
"Opt2",
"Opt3");
final ComboBox comboBox = new ComboBox(options);
pagination = new Pagination((data.size() / rowsPerPage() + 1), 0);
// pagination = new Pagination(20 , 0);
pagination.setStyle("-fx-border-color:red;");
pagination.setPageFactory(new Callback<Integer, Node>() {
@Override
public Node call(Integer pageIndex) {
if (pageIndex > data.size() / rowsPerPage() + 1) {
return null;
} else {
return createPage(pageIndex);
AnchorPane anchor = new AnchorPane();
AnchorPane.setTopAnchor(pagination, 10.0);
AnchorPane.setRightAnchor(pagination, 10.0);
AnchorPane.setBottomAnchor(pagination, 10.0);
AnchorPane.setLeftAnchor(pagination, 10.0);
Scene scene = new Scene(anchor, 400, 250);
AnchorPane.setBottomAnchor(comboBox, 40.0);
AnchorPane.setLeftAnchor(comboBox, 12.0);
anchor.getChildren().addAll(pagination, comboBox);
stage.setScene(scene);
stage.setTitle("Table pager");
stage.show();
public static class Person {
private final SimpleStringProperty num;
private final SimpleStringProperty firstName;
private final SimpleStringProperty lastName;
private Person(String id, String fName, String lName) {
this.firstName = new SimpleStringProperty(fName);
this.lastName = new SimpleStringProperty(lName);
this.num = new SimpleStringProperty(id);
public String getFirstName() {
return firstName.get();
public void setFirstName(String fName) {
firstName.set(fName);
public String getLastName() {
return lastName.get();
public void setLastName(String fName) {
lastName.set(fName);
public String getNum() {
return num.get();
public void setNum(String id) {
num.set(id); -
Needs multi column dynamic combo box using C#
I need a dynamic Combo box to display multi columns on Drop Down Event
such as Stock Code, Make, Model,Sub Model, Measurement Type and so on for my C# Application with Columns Headers
Please Help Me
Thanks in AdvanceYou should create a class that represents your model and then you could use a CompositeCollection as the ItemsSource of the ComboBox.
Here is an example for you:
namespace WpfApplication59
public class YourModel
public string StockCode { get; set; }
public string Model { get; set; }
//+ the rest of your properties
MainWindow.xaml.cs:
public partial class MainWindow : Window
public MainWindow()
InitializeComponent();
List<YourModel> models = new List<YourModel>();
models.Add(new YourModel() { Model = "m1", StockCode ="c1"});
models.Add(new YourModel() { Model = "m2", StockCode = "c2" });
cb.ItemsSource = models;
MainWindow.xaml:
<ComboBox x:Name="cb" Grid.IsSharedSizeScope="True" ItemsSource="{DynamicResource items}"
xmlns:local="clr-namespace:WpfApplication59">
<ComboBox.Resources>
<CompositeCollection x:Key="items">
<ComboBoxItem IsEnabled="False">
<Grid TextElement.FontWeight="Bold">
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="A"/>
<ColumnDefinition Width="5"/>
<ColumnDefinition SharedSizeGroup="B"/>
</Grid.ColumnDefinitions>
<Grid.Children>
<TextBlock Grid.Column="0" Text="Model"/>
<TextBlock Grid.Column="2" Text="Stock Code"/>
</Grid.Children>
</Grid>
</ComboBoxItem>
<Separator/>
<CollectionContainer Collection="{Binding Source={x:Reference cb}, Path=DataContext}"/>
</CompositeCollection>
<DataTemplate DataType="{x:Type local:YourModel}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="A"/>
<ColumnDefinition Width="5"/>
<ColumnDefinition SharedSizeGroup="B"/>
</Grid.ColumnDefinitions>
<Grid.Children>
<TextBlock Grid.Column="0" Text="{Binding Model}"/>
<TextBlock Grid.Column="2" Text="{Binding StockCode}"/>
</Grid.Children>
</Grid>
</DataTemplate>
</ComboBox.Resources>
</ComboBox>
You could restyle the the templates (Grids) as per your requirements.
Please remember to mark helpful posts as answer to close your threads and then start a new thread if you have a new question. -
Trying to filter an entire database using a combo box or text box
Hi,
I am looking to create a combo box with rows vice columns, then I would like to create a macro or some for form of filter that gives me the option to search within each or all of the selections.
I have created a search function (using a textbox and the button features) that allows me to search for anything in my database using applyfilter. The problem that I ran into with this was that when I hit the might work, but only the first line worked.
So I tried to use a combination box to create a filter of the fields that I want to view for the particular search I need, but I want to select row headers vice columns of information. For example if I have five fields of: Last Name, First Name, SSN, Document
number and Unique ID.
I want a combination box to show the following field header when I click the drop down option.
(Last Name
First Name
SSN
Documentation Number
Unique ID)
Then I would to apply a macro filter feature for files within theses individual fields. I am just getting started in VBA and using Macros, so any help would be awesome!!
If I am too far off target please direct me back, I tend to over think things.
Thanks in AdvanceDirk Goldgar, I tried to you use the suggested method you gave me. Part of the problem I was having was that I wanted to view the field list, which I now know is very possible thanks to you, but only wanted it to show as one single list of fields.
So took the information you gave me and went on to create a list box instead. I later found out why this was not working either.
In what way was it not working? You can do the same thing with a list box as I described for a combo box.
I have relationships of tables attached.
I don't understand what you mean by that last statement, or how it's relevant to the discussion. Do you mean you have multiple different tables that you might want to filter? So you would need to either (a) first need to select a table from a
list of tables in your database, and only then select a field in that table, or else (b) have a table listing all the data elements you might want to search, with the table and field name of each, and base a list box on that -- then the code to search would
know what table to select from, as well as what field to filter on.
So this info that you provided was very helpful. I will continue to go through the link you provided.
So I can quickly sum up what I need:
1. A dropdown box that allows me to search any Field List
2. A textbox that allows me to type in the searchable information for that particular field.
3. Or some way to build a filter function for the whole list, with a textbox to search the key words.
This is all still a bit unclear to me, because I don't know whether you want to search a particular table, or any of many possible tables in the database.
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html -
Editable Combo box in a JTable
Hi,
Is it possible to have an editable combo Box in a JTable with an item Listener attached to the combo Box?
Based on whatever value the user enters in that column that is rendered as a combo Box(editable) i should be able to do some validation. Is this possible?
Thanks in advance for your time and patience.
ArchanaHere's a start:
public class FileModel5 extends AbstractTableModel
public boolean isEditable = false;
protected static int NUM_COLUMNS = 3;
// initialize number of rows to start out with ...
protected static int START_NUM_ROWS = 0;
protected int nextEmptyRow = 0;
protected int numRows = 0;
static final public String file = "File";
static final public String mailName = "Mail Id";
static final public String postName = "Post Office Id";
static final public String columnNames[] = {"File", "Mail Id", "Post Office Id"};
// List of data
protected Vector data = null;
public FileModel5()
data = new Vector();
public boolean isCellEditable(int rowIndex, int columnIndex)
// The 2nd & 3rd column or Value field is editable
if(isEditable)
if(columnIndex > 0)
return true;
return false;
* JTable uses this method to determine the default renderer/
* editor for each cell. If we didn't implement this method,
* then the last column would contain text ("true"/"false"),
* rather than a check box.
public Class getColumnClass(int c)
return getValueAt(0, c).getClass();
* Retrieves number of columns
public synchronized int getColumnCount()
return NUM_COLUMNS;
* Get a column name
public String getColumnName(int col)
return columnNames[col];
* Retrieves number of records
public synchronized int getRowCount()
if (numRows < START_NUM_ROWS)
return START_NUM_ROWS;
else
return numRows;
* Returns cell information of a record at location row,column
public synchronized Object getValueAt(int row, int column)
try
FileRecord5 p = (FileRecord5)data.elementAt(row);
switch (column)
case 0:
return (String)p.file;
case 1:
return (String)p.mailName;
case 2:
return (String)p.postName;
catch (Exception e)
return "";
public void setValueAt(Object aValue, int row, int column)
FileRecord5 arow = (FileRecord5)data.elementAt(row);
arow.setElementAt((String)aValue, column);
fireTableCellUpdated(row, column);
* Returns information of an entire record at location row
public synchronized FileRecord5 getRecordAt(int row) throws Exception
try
return (FileRecord5)data.elementAt(row);
catch (Exception e)
throw new Exception("Record not found");
* Used to add or update a record
* @param tableRecord
public synchronized void updateRecord(FileRecord5 tableRecord)
String file = tableRecord.file;
FileRecord5 p = null;
int index = -1;
boolean found = false;
boolean addedRow = false;
int i = 0;
while (!found && (i < nextEmptyRow))
p = (FileRecord5)data.elementAt(i);
if (p.file.equals(file))
found = true;
index = i;
} else
i++;
if (found)
{ //update
data.setElementAt(tableRecord, index);
else
if (numRows <= nextEmptyRow)
//add a row
numRows++;
addedRow = true;
index = nextEmptyRow;
data.addElement(tableRecord);
//Notify listeners that the data changed.
if (addedRow)
nextEmptyRow++;
fireTableRowsInserted(index, index);
else
fireTableRowsUpdated(index, index);
* Used to delete a record
public synchronized void deleteRecord(String file)
FileRecord5 p = null;
int index = -1;
boolean found = false;
int i = 0;
while (!found && (i < nextEmptyRow))
p = (FileRecord5)data.elementAt(i);
if (p.file.equals(file))
found = true;
index = i;
} else
i++;
if (found)
data.removeElementAt(i);
nextEmptyRow--;
numRows--;
fireTableRowsDeleted(START_NUM_ROWS, numRows);
* Clears all records
public synchronized void clear()
int oldNumRows = numRows;
numRows = START_NUM_ROWS;
data.removeAllElements();
nextEmptyRow = 0;
if (oldNumRows > START_NUM_ROWS)
fireTableRowsDeleted(START_NUM_ROWS, oldNumRows - 1);
fireTableRowsUpdated(0, START_NUM_ROWS - 1);
* Loads the values into the combo box within the table for mail id
public void setUpMailColumn(JTable mapTable, ArrayList mailList)
TableColumn col = mapTable.getColumnModel().getColumn(1);
javax.swing.JComboBox comboMail = new javax.swing.JComboBox();
int s = mailList.size();
for(int i=0; i<s; i++)
comboMail.addItem(mailList.get(i));
col.setCellEditor(new DefaultCellEditor(comboMail));
//Set up tool tips.
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setToolTipText("Click for mail Id list");
col.setCellRenderer(renderer);
//Set up tool tip for the mailName column header.
TableCellRenderer headerRenderer = col.getHeaderRenderer();
if (headerRenderer instanceof DefaultTableCellRenderer)
((DefaultTableCellRenderer)headerRenderer).setToolTipText(
"Click the Mail Id to see a list of choices");
* Loads the values into the combo box within the table for post office id
public void setUpPostColumn(JTable mapTable, ArrayList postList)
TableColumn col = mapTable.getColumnModel().getColumn(2);
javax.swing.JComboBox combo = new javax.swing.JComboBox();
int s = postList.size();
for(int i=0; i<s; i++)
combo.addItem(postList.get(i));
col.setCellEditor(new DefaultCellEditor(combo));
//Set up tool tips.
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setToolTipText("Click for post office Id list");
col.setCellRenderer(renderer);
//Set up tool tip for the mailName column header.
TableCellRenderer headerRenderer = col.getHeaderRenderer();
if (headerRenderer instanceof DefaultTableCellRenderer)
((DefaultTableCellRenderer)headerRenderer).setToolTipText(
"Click the Post Office Id to see a list of choices");
} -
Problem in event handling of combo box in JTable cell
Hi,
I have a combo box as an editor for a column cells in JTable. I have a event listener for this combo box. When ever I click on the JTable cell whose editor is combo box,
I get the following exception,
Exception occurred during event dispatching:
java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTableUI$MouseInputHandler.setDispatchComponent(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI$MouseInputHandler.mousePressed(Unknown Source)
at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Can any one tell me how to over come this problem.
Thanks,
RaghuHere's an example of the model I used in my JTable. I've placed 2 comboBoxes with no problems.
Hope this helps.
public class FileModel5 extends AbstractTableModel
public boolean isEditable = false;
protected static int NUM_COLUMNS = 3;
// initialize number of rows to start out with ...
protected static int START_NUM_ROWS = 0;
protected int nextEmptyRow = 0;
protected int numRows = 0;
static final public String file = "File";
static final public String mailName = "Mail Id";
static final public String postName = "Post Office Id";
static final public String columnNames[] = {"File", "Mail Id", "Post Office Id"};
// List of data
protected Vector data = null;
public FileModel5()
data = new Vector();
public boolean isCellEditable(int rowIndex, int columnIndex)
// The 2nd & 3rd column or Value field is editable
if(isEditable)
if(columnIndex > 0)
return true;
return false;
* JTable uses this method to determine the default renderer/
* editor for each cell. If we didn't implement this method,
* then the last column would contain text ("true"/"false"),
* rather than a check box.
public Class getColumnClass(int c)
return getValueAt(0, c).getClass();
* Retrieves number of columns
public synchronized int getColumnCount()
return NUM_COLUMNS;
* Get a column name
public String getColumnName(int col)
return columnNames[col];
* Retrieves number of records
public synchronized int getRowCount()
if (numRows < START_NUM_ROWS)
return START_NUM_ROWS;
else
return numRows;
* Returns cell information of a record at location row,column
public synchronized Object getValueAt(int row, int column)
try
FileRecord5 p = (FileRecord5)data.elementAt(row);
switch (column)
case 0:
return (String)p.file;
case 1:
return (String)p.mailName;
case 2:
return (String)p.postName;
catch (Exception e)
return "";
public void setValueAt(Object aValue, int row, int column)
FileRecord5 arow = (FileRecord5)data.elementAt(row);
arow.setElementAt((String)aValue, column);
fireTableCellUpdated(row, column);
* Returns information of an entire record at location row
public synchronized FileRecord5 getRecordAt(int row) throws Exception
try
return (FileRecord5)data.elementAt(row);
catch (Exception e)
throw new Exception("Record not found");
* Used to add or update a record
* @param tableRecord
public synchronized void updateRecord(FileRecord5 tableRecord)
String file = tableRecord.file;
FileRecord5 p = null;
int index = -1;
boolean found = false;
boolean addedRow = false;
int i = 0;
while (!found && (i < nextEmptyRow))
p = (FileRecord5)data.elementAt(i);
if (p.file.equals(file))
found = true;
index = i;
} else
i++;
if (found)
{ //update
data.setElementAt(tableRecord, index);
else
if (numRows <= nextEmptyRow)
//add a row
numRows++;
addedRow = true;
index = nextEmptyRow;
data.addElement(tableRecord);
//Notify listeners that the data changed.
if (addedRow)
nextEmptyRow++;
fireTableRowsInserted(index, index);
else
fireTableRowsUpdated(index, index);
* Used to delete a record
public synchronized void deleteRecord(String file)
FileRecord5 p = null;
int index = -1;
boolean found = false;
int i = 0;
while (!found && (i < nextEmptyRow))
p = (FileRecord5)data.elementAt(i);
if (p.file.equals(file))
found = true;
index = i;
} else
i++;
if (found)
data.removeElementAt(i);
nextEmptyRow--;
numRows--;
fireTableRowsDeleted(START_NUM_ROWS, numRows);
* Clears all records
public synchronized void clear()
int oldNumRows = numRows;
numRows = START_NUM_ROWS;
data.removeAllElements();
nextEmptyRow = 0;
if (oldNumRows > START_NUM_ROWS)
fireTableRowsDeleted(START_NUM_ROWS, oldNumRows - 1);
fireTableRowsUpdated(0, START_NUM_ROWS - 1);
* Loads the values into the combo box within the table for mail id
public void setUpMailColumn(JTable mapTable, ArrayList mailList)
TableColumn col = mapTable.getColumnModel().getColumn(1);
javax.swing.JComboBox comboMail = new javax.swing.JComboBox();
int s = mailList.size();
for(int i=0; i<s; i++)
comboMail.addItem(mailList.get(i));
col.setCellEditor(new DefaultCellEditor(comboMail));
//Set up tool tips.
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setToolTipText("Click for mail Id list");
col.setCellRenderer(renderer);
//Set up tool tip for the mailName column header.
TableCellRenderer headerRenderer = col.getHeaderRenderer();
if (headerRenderer instanceof DefaultTableCellRenderer)
((DefaultTableCellRenderer)headerRenderer).setToolTipText(
"Click the Mail Id to see a list of choices");
* Loads the values into the combo box within the table for post office id
public void setUpPostColumn(JTable mapTable, ArrayList postList)
TableColumn col = mapTable.getColumnModel().getColumn(2);
javax.swing.JComboBox combo = new javax.swing.JComboBox();
int s = postList.size();
for(int i=0; i<s; i++)
combo.addItem(postList.get(i));
col.setCellEditor(new DefaultCellEditor(combo));
//Set up tool tips.
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setToolTipText("Click for post office Id list");
col.setCellRenderer(renderer);
//Set up tool tip for the mailName column header.
TableCellRenderer headerRenderer = col.getHeaderRenderer();
if (headerRenderer instanceof DefaultTableCellRenderer)
((DefaultTableCellRenderer)headerRenderer).setToolTipText(
"Click the Post Office Id to see a list of choices");
} -
Me and a co-worker are trying to learn the Designer for a proof of concept (yes, that means newbies). We are currently struggling with loading a dropdown combo box from a table in an MS Access database. We have the connection set up and the field assigned to the control. It populates with the first record from the table, but clicking on the dropdown button does nothing. Is it only populating with one record? Is there a property on the control that is not allowing the list to expand?
I saw another thread in this forum on this topic and the last entry in the thread included the phrase "I GAVE UP" - not very encouraging. This functionality is a must-have and seems pretty basic.
Any advice?I have been trying this using a Data Drop-down List and I cannot get it work. I have a data connection set up and instead of selecting Table from the choice I used an SQL query to select only one column in the table. There are three lines in the script some of which are confusing to me.<br /><br />var sDataConnectionName = "DataConnection"; //I got this one. it was easy<br />var sColHiddenValue = "<value>";<br />var sColDisplayText = "<value>";<br /><br />The last two I'm really not sure what to put there. I tried putting the name of the table column in place of each of "<value>". but it doesn't work.<br /><br />What else do I need to do to get it to work?
-
Combine table 3 columns in a combo box?
I need a combo box to display "lastName, firstName - phone".
I have these 3 columns in my database. Can anyone provide a short
cfc to xml script I could use to create an arrayCollection to use
as a dataprovider for my combobox?
I'm thinking along the lines of a CFQUERY in a cfc, then
exporting the results to an xml structure and using the xml as an
array collection. I just don't know how to do the cfc -> xml.
Any alternative solutions are welcome also. thanksBleh, double posted this due to forum maintenance.
-
I am developing a desktop application in Wpf using MVVM and Entity Frameworks. I have the following tables:
1. Party (PartyId, Name)
2. Case (CaseId, CaseNo)
3. Petitioner (CaseId, PartyId) ............. Link Table
I am completely new to .Net and to begin with I download Microsoft's sample application and
following the pattern I have been successful in creating several tabs. The problem started only when I wanted to implement many-to-many relationship. The sample application has not covered the scenario where there can be a any-to-many relationship. However
with the help of MSDN forum I came to know about a link table and managed to solve entity framework issues pertaining to many-to-many relationship. Here is the screenshot of my application to show you what I have achieved so far.
And now the problem I want the forum to address is how to bind a combo box so that it retrieves Party.Name for the corresponding PartyId in the Link Table and also I want to populate it with Party.Name so that
users can choose one from the dropdown list to add or edit the petitioner.Hello Barry,
Thanks a lot for responding to my query. As I am completely new to .Net and following the pattern of Microsoft's Employee Tracker sample it seems difficult to clearly understand the concept and implement it in a scenario which is different than what is in
the sample available at the link you supplied.
To get the idea of the thing here is my code behind of a view vBoxPetitioner:
<UserControl x:Class="CCIS.View.Case.vBoxPetitioner"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:v="clr-namespace:CCIS.View.Case"
xmlns:vm="clr-namespace:CCIS.ViewModel.Case"
mc:Ignorable="d"
d:DesignWidth="300"
d:DesignHeight="200">
<UserControl.Resources>
<DataTemplate DataType="{x:Type vm:vmPetitioner}">
<v:vPetitioner Margin="0,2,0,0" />
</DataTemplate>
</UserControl.Resources>
<Grid>
<HeaderedContentControl>
<HeaderedContentControl.Header>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<TextBlock Margin="2">
<Hyperlink Command="{Binding Path=AddPetitionerCommand}">Add Petitioner</Hyperlink>
| <Hyperlink Command="{Binding Path=DeletePetitionerCommand}">Delete</Hyperlink>
</TextBlock>
</StackPanel>
</HeaderedContentControl.Header>
<ListBox BorderThickness="0" SelectedItem="{Binding Path=CurrentPetitioner, Mode=TwoWay}" ItemsSource="{Binding Path=tblParties}" />
</HeaderedContentControl>
</Grid>
</UserControl>
This part is working fine as it loads another view that is vPetioner perfectly in the manner I want it to be.
Here is the code of vmPetitioner, a ViewModel:
Imports Microsoft.VisualBasic
Imports System.Collections.ObjectModel
Imports System
Imports CCIS.Model.Party
Namespace CCIS.ViewModel.Case
''' <summary>
''' ViewModel of an individual Email
''' </summary>
Public Class vmPetitioner
Inherits vmParty
''' <summary>
''' The Email object backing this ViewModel
''' </summary>
Private petitioner As tblParty
''' <summary>
''' Initializes a new instance of the EmailViewModel class.
''' </summary>
''' <param name="detail">The underlying Email this ViewModel is to be based on</param>
Public Sub New(ByVal detail As tblParty)
If detail Is Nothing Then
Throw New ArgumentNullException("detail")
End If
Me.petitioner = detail
End Sub
''' <summary>
''' Gets the underlying Email this ViewModel is based on
''' </summary>
Public Overrides ReadOnly Property Model() As tblParty
Get
Return Me.petitioner
End Get
End Property
''' <summary>
''' Gets or sets the actual email address
''' </summary>
Public Property fldPartyId() As String
Get
Return Me.petitioner.fldPartyId
End Get
Set(ByVal value As String)
Me.petitioner.fldPartyId = value
Me.OnPropertyChanged("fldPartyId")
End Set
End Property
End Class
End Namespace
And below is the ViewMode vmParty which vmPetitioner Inherits:
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports CCIS.Model.Case
Imports CCIS.Model.Party
Imports CCIS.ViewModel.Helpers
Namespace CCIS.ViewModel.Case
''' <summary>
''' Common functionality for ViewModels of an individual ContactDetail
''' </summary>
Public MustInherit Class vmParty
Inherits ViewModelBase
''' <summary>
''' Gets the underlying ContactDetail this ViewModel is based on
''' </summary>
Public MustOverride ReadOnly Property Model() As tblParty
'''' <summary>
'''' Gets the underlying ContactDetail this ViewModel is based on
'''' </summary>
'Public MustOverride ReadOnly Property Model() As tblAdvocate
''' <summary>
''' Gets or sets the name of this department
''' </summary>
Public Property fldName() As String
Get
Return Me.Model.fldName
End Get
Set(ByVal value As String)
Me.Model.fldName = value
Me.OnPropertyChanged("fldName")
End Set
End Property
''' <summary>
''' Constructs a view model to represent the supplied ContactDetail
''' </summary>
''' <param name="detail">The detail to build a ViewModel for</param>
''' <returns>The constructed ViewModel, null if one can't be built</returns>
Public Shared Function BuildViewModel(ByVal detail As tblParty) As vmParty
If detail Is Nothing Then
Throw New ArgumentNullException("detail")
End If
Dim e As tblParty = TryCast(detail, tblParty)
If e IsNot Nothing Then
Return New vmPetitioner(e)
End If
Return Nothing
End Function
End Class
End Namespace
And final the code behind of the view vPetitioner:
<UserControl x:Class="CCIS.View.Case.vPetitioner"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:vm="clr-namespace:CCIS.ViewModel.Case"
mc:Ignorable="d"
Width="300">
<UserControl.Resources>
<ResourceDictionary Source=".\CompactFormStyles.xaml" />
</UserControl.Resources>
<Grid>
<Border Style="{StaticResource DetailBorder}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="Petitioner:" />
<ComboBox Grid.Column="1" Width="240" SelectedValuePath="." SelectedItem="{Binding Path=tblParty}" ItemsSource="{Binding Path=PetitionerLookup}" DisplayMemberPath="fldName" />
</Grid>
</Border>
</Grid>
</UserControl>
The problem, presumably, seems to be is that the binding path "PetitionerLookup" of the ItemSource of the Combo box in the view vPetitioner exists in a different ViewModel vmCase which serves as an ObservableCollection for MainViewModel. Therefore,
what I need to Know is how to route the binding path if it exists in a different ViewModel?
Sir, I look forward to your early reply bringing a workable solution to the problem I face.
Warm Regards,
Arun -
Access 2010 - How to display data from a table into a text box upon combo box selection?
Hi
I have a a table with 5 columns: month, year, USD, SGD, BAHT.
I created a form with a combo box for selection of the month and year, and I would like to set adjacent text boxes to show USD, SGD, BAHT information. How can i go about doing that?
From the Q&A here, most of them uses the function similar to this "=[Combo0].[Column](1)" to show the data in the text box, but this would require the combo box to list a whole bunch of details if i were to add in more currency values to the
table. Is it possible to not show this information in the combo box, but still populate data in the textboxes base on a selection on only the "month" and "year" in the combo box.Hi,
According to your description, my understanding is that you want to show only the month/year in the combo box, we can choose the date, and it will display the value of USD/SGD/BAHT based on the month/year.
If it is, I recommend you try the steps:
Create a form based on your data source table>Add the combo box>combo box wizard>Find a record on my form based on the value I selected my combo box>Add mouth and year to selected fields
http://office.microsoft.com/en-us/access-help/create-a-list-of-choices-by-using-a-list-box-or-combo-box-HA010113052.aspx
If I misunderstand something, please let me know. We may upload some screenshots or a sample through OneDrive.
Regards,
George Zhao
TechNet Community Support
Maybe you are looking for
-
Hi, I have this XML that is returned from a ColdFusion CFC. So in Flex I have this code: var treeXML:XML = new XML(event.result); I am then assigning this to the dataProvider of my tree. This works fine, but how can I get at each top level node in th
-
Business Object for Characteristics
Hello Experts We are planning to trigger workflow when a vlue is change to a particular value to a Characteristics. What Business Object Type should we use for this? Thanks Ankit
-
Installed 8.5 and now I can't build an installer with 8.0
I've been using 8.0 to write some applications. We have the professional development system contract or whatever with NI providing upgrades. Our IT dept came and installed 8.5 on my computer. I used it for a short while, then went back to 8.0. I
-
WLAN vs. mobile services
How do I know wheter my blackberry is working of WLAN or the mobile services when both is switched on? Is there somewhere an option to select "use wlan over mobile service"? Especially when travelling international stronger use of WLAN is much more c
-
How can I extend the wireless range on my BT Hub 3
I currently have the BT hub 3 and find that as I have quite a rambling house and the broadband is located at one side rather than in the middle of the house I cannot get a signal in all areas. This is massively frustration for the children when they