We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Combobox + browse button

Hi, I'm using v5.

I'm looking to make a cell that has the functionality of a combo box plus have another button (i.e. [...]) that will allow the user to load up another form. I can make a cell that does both of these, but not sure what the best approach is for combining them.

Should I be inheriting from GridCellComboBoxButton, GridCellComboBoxModel, GridCellComboBoxRenderer and then adding my own browse button? We only have the binaries so I don't know if it's going to hurt that I can't see the underlying code.

Thanks for any advice.

Dan

2 Replies

HA haneefm Syncfusion Team May 25, 2007 03:09 PM UTC

Hi Dan,

You can show two buttons in the cell where you now have one. You can do it by deriving the GridComboBoxCellrenderer class. In that renderer's constructor you can add another button by using the AddButton method. Below is a forum thread that show this task.

http://www.syncfusion.com/support/Forums/message.aspx?&MessageID=61114

Let me know if this helps.

Best regards,
Haneef


DD Dan Dorey May 25, 2007 06:08 PM UTC

Thanks! I was able to figure it out from that example. It was slightly different in 5.0. I'll paste what I ended up with in case it's useful to anyone else.

using System;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.Serialization;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;

using Syncfusion.Diagnostics;
using Syncfusion.Windows.Forms.Grid;

namespace Syncfusion.Windows.Forms.Diagram.Samples.DiagramTool.Pages
{


[Serializable]
public class PlaylistCellModel : GridComboBoxCellModel
{

protected PlaylistCellModel(SerializationInfo info, StreamingContext context)
: base(info, context)
{
this.ButtonBarSize = new Size(50, 50);
}


public PlaylistCellModel(GridModel grid)
: base(grid)
{
}


public override GridCellRendererBase CreateRenderer(GridControlBase control)
{
return new PlaylistCellRenderer(control, this);
}



protected override Size OnQueryPrefferedClientSize(Graphics g, int rowIndex, int colIndex, GridStyleInfo style, GridQueryBounds GridQueryBounds)
{
Size size = base.OnQueryPrefferedClientSize(g, rowIndex, colIndex, style, GridQueryBounds);
return new Size(size.Width + 50, size.Height); // base method already consides ButtonBarSize, but let's add some more pixels here.
}


}


public class PlaylistCellRenderer : GridComboBoxCellRenderer
{

public PlaylistCellRenderer(GridControlBase grid, GridTextBoxCellModel cellModel)
: base(grid, cellModel)
{
this.SupportsFocusControl = false;

GridCellButton button = new GridCellButton(this);
button.Text = "...";
AddButton(button);
button.Clicked += new GridCellEventHandler(button_Clicked);

}

void button_Clicked(object sender, GridCellEventArgs e)
{
MessageBox.Show("hi");
}


protected override System.Drawing.Rectangle OnLayout(int rowIndex, int colIndex, GridStyleInfo style, System.Drawing.Rectangle innerBounds, System.Drawing.Rectangle[] buttonsBounds)
{

// buttonBounds[] defines the location of where the buttons are drawn.
// innnerBounds is the rectangle of the entire cell

// Define the rectangles that will contain our buttons (we're button the combo arrow before the [...]
System.Drawing.Rectangle comboButtonBounds = System.Drawing.Rectangle.FromLTRB(innerBounds.Right - 40, innerBounds.Top, innerBounds.Right -20, innerBounds.Bottom);
System.Drawing.Rectangle ellipseButtonBounds = System.Drawing.Rectangle.FromLTRB(innerBounds.Right - 20, innerBounds.Top, innerBounds.Right, innerBounds.Bottom);

// The underlying code will have already set the location of the combo button, but we have to move it over to the left.
// Since that was the first button used, it will be index 0. We then set the location of our new [...] button.
buttonsBounds[0] = comboButtonBounds;
buttonsBounds[1] = ellipseButtonBounds;


// this is how much space between the buttons and the text to the left of it.
innerBounds.Width -= 20;
return innerBounds;
}



}

}


Loader.
Live Chat Icon For mobile
Up arrow icon