0

Selecting Cell in a ListBox

asked 2008-07-22 10:28:51 +0800

natnan gravatar image natnan
27

Hi,

how can i make the user select only a cell,not the whole row in a listbox?
or should i use different component?

thanks.

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2008-07-22 16:37:36 +0800

ansancle gravatar image ansancle
317 9

Im 99.99% sure you can't just select a cell, use a different component, depending upon what you are doing look at the tree or the grid.

link publish delete flag offensive edit

answered 2008-07-23 07:08:30 +0800

natnan gravatar image natnan
27

well,i'm trying to create something like agenda.It seems grid is the one that i should use

but what should i add into the cells that is selectable?

link publish delete flag offensive edit

answered 2008-07-23 12:24:25 +0800

ansancle gravatar image ansancle
317 9

You can add any component you want into a grid cell, I have a few different grids that I create dynamically in java and use buttons. But I use css classes so that you only see an image instead of a traditional button, but you can do whatever you want.

The sample code below is the render method from my GridRowRenderer which implements ZK's RowRenderer.
The data in this case is a 2 dimensional array of users so that my grid has 2 columns of data. If you follow along in the code
you can see that depending upon if images are found in the db or not I add different component types into each grid column and row.

The sample code below the render method from my GridRowRenderer which implements RowRenderer.
The data in this case is a 2 dimensional array so that my grid has 2 columns of data. If you follow along in the code
you can see that depending upon if images are found etc. I add different component types into each grid column and row.



Here are the two .css classes used by this code : 

.userButton
{	
    border: none;
    font-size: xx-small; 
    font-weight: normal;
    background : transparent;
    font : icon;		
}

.unknownUserImage
{
    background : URL(./images/user/UnkownUserSmall.jpg) no-repeat center;
    border: none;
    font: icon;
    font-size:xsmall;
    height : 32px;
    width : 32px;
}



	public void render(Row row, Object rowData) throws Exception
	{
				
		try
		{
			
			// for a user gird, we are expecting 2 rows of data, a 2 dimensional array.
			DHeUser[] userRowData = (DHeUser[])rowData;
			
			// 2 Columns of data
			DHeUser user1 = userRowData[0];
			DHeUser user2 = userRowData[1];
			if (user1 != null)
			{
                                // Look in the database for an image for this user
				org.zkoss.image.Image zkImage = DHzZKUtilities.getZKImageForUser(user1);
                                // Create the button that is going in column1 and give it a label equal to the username
				Button userButton1 = new Button(user1.getUserName());
                                // If we found an image for this user we set it into the button
				if (zkImage != null)
				{
					userButton1.setImageContent(zkImage);
					userButton1.setSclass("userButton");
					userButton1.setParent(row);					
				}
				else // If we don't have an image in the DB for this user. We use the unknownUserButton sclass
				{
			                Vbox vbox = new Vbox();
			                vbox.setPack("center");    
			                vbox.setAlign("center");					
							userButton1.setSclass("unknownUserButton");	
							userButton1.setLabel("");
							userButton1.setParent(vbox);					
			                Label buttonLabel = new Label(user1.getUserName());
			                buttonLabel.setSclass("dhUISmallIconFont");
			                buttonLabel.setParent(vbox);		                
			                vbox.setParent(row);
				}
				userButton1.setWidth(new String(componentWidth + "px"));
				userButton1.setId("usergridbuttonColumn1" + System.currentTimeMillis() + DHzZKUtilities.seperator + user1.getId());
				userButton1.addEventListener("onClick", userSelectListener);				
				userButton1.setOrient("vertical");
				
			}
			else
			{
				Label emptyLabel = new Label();
				emptyLabel.setParent(row);
			}
			if (user2 != null)
			{ 
				org.zkoss.image.Image zkImage = DHzZKUtilities.getZKImageForUser(user2);				
				Button userButton2 = new Button(user2.getUserName());
				if (zkImage != null)
				{
					userButton2.setImageContent(zkImage);
					userButton2.setSclass("userButton");
					userButton2.setParent(row);		
				}				
				else
				{
			                Vbox vbox = new Vbox();
			                vbox.setPack("center");    
			                vbox.setAlign("center");					
							userButton2.setSclass("unknownUserButton");	
							userButton2.setLabel("");
							userButton2.setParent(vbox);					
			                Label buttonLabel = new Label(user2.getUserName());
			                buttonLabel.setSclass("dhUISmallIconFont");
			                buttonLabel.setParent(vbox);		                
			                vbox.setParent(row);
				}
				userButton2.setWidth(new String(componentWidth + "px"));
				userButton2.setId("usergridbuttonColumn2" + System.currentTimeMillis() + DHzZKUtilities.seperator + user2.getId());
				userButton2.addEventListener("onClick", userSelectListener);						
				userButton2.setOrient("vertical");				
			}			
			else
			{
				Label emptyLabel = new Label();
				emptyLabel.setParent(row);
			}						
		}
		catch(Exception e)
		{
			logger.error("DHzUserGridRowRenderer render method. Exception caught : " + e.getMessage(),e);
			throw e;
		}		
	}

link publish delete flag offensive edit

answered 2008-11-28 01:13:40 +0800

judacoor gravatar image judacoor
280 1 3 8

Hi ansancle and thanks for your post!

Could you please explain or go a little deeper into userSelectListener, please?

That's the part I'm having trouble with.

Thanks,
judacoor

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2008-07-22 10:28:51 +0800

Seen: 338 times

Last updated: Nov 28 '08

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More