private void Button1_Click(object sender, System.EventArgs e)
{
if(this.UltraWebGrid1.DisplayLayout.SelectedCells.Count>0)
{
//create variables to hold the min/max column and row
int colMin =this.UltraWebGrid1.DisplayLayout.SelectedCells[0].Column.Index;
int colMax = this.UltraWebGrid1.DisplayLayout.SelectedCells[0].Column.Index;
int rowMin = this.UltraWebGrid1.DisplayLayout.SelectedCells[0].Row.Index;
int rowMax = this.UltraWebGrid1.DisplayLayout.SelectedCells[0].Row.Index;
             //determine the min/max column and row
foreach(UltraGridCell aCell in this.UltraWebGrid1.DisplayLayout.SelectedCells)
{
if(aCell.Column.Index < colMin)
colMin=aCell.Column.Index;
if(aCell.Column.Index > colMax)
colMax=aCell.Column.Index;
if(aCell.Row.Index < rowMin)
rowMin=aCell.Row.Index;
if(aCell.Row.Index > rowMax)
rowMax=aCell.Row.Index; }

//get a reference to the top left most cell to use for the merge
UltraGridCell cell=this.UltraWebGrid1.Rows[rowMin].Cells[colMin];
//deactivate the current activecell
cell.Activated=false;
//create a variable to control the loop for the selected cells
// you must get this now because as you deselect cells the count decreases
// so if you use for(short i=0;i<selectedCells.count; i++) then the loop will 
//will exit prematurely since selectedCell.count will be decreasing inside the loop

//deselect the currently selected cells
int x=this.UltraWebGrid1.DisplayLayout.SelectedCells.Count;
for(short i=0;i<x; i++)
this.UltraWebGrid1.DisplayLayout.SelectedCells[this.UltraWebGrid1.DisplayLayout.SelectedCells.Count-1].Selected=false;
// set the col span and row span based upon the min/max column and row
cell.ColSpan=colMax-colMin+1;
cell.RowSpan=rowMax-rowMin+1;
//get a reference to the row
UltraGridRow row=cell.Row;
//set the merged cell at the coluymn index of the top/left most cell
//set an image for the merged cell
cell.Style.BackgroundImage="image/ig_logo.gif";
cell.Style.CustomRules="background-repeat:no-repeat;background-position:center center;";
cell.Text = "";
//set thge new merged cell as active
this.UltraWebGrid1.DisplayLayout.ActiveCell=cell; }


}

解决方案 »

  1.   

    急:楼上的兄弟是在Web的UltraWebGrid1 控件下的操作, 请问在 WinForm的控件下怎样操作 ?
      

  2.   

    帮助里面没有讲到Merge()的东西。你有没有 例子,可借我看一下。
      

  3.   

    楼主看看这个,也许对你有所帮助
    http://www.csdn.net/develop/Read_Article.asp?Id=24441
    http://www.csdn.net/develop/Read_Article.asp?Id=24432
      

  4.   

    好象winform 的UltraGrid 没有合并功能吧,我也没找到它的合并功能 ,改用别的控件了,
      

  5.   

    luaiping(luaiping): 
       你上面写的代码是不是有遗漏的地方, 你能不能留下联系方式,我想向你请教一下。