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;
}
}
}