private sub unitdatagriditem(byval intcell as integer) dim objdatagriditem as datagriditem dim strcell1 as string = "" dim strcell2 as string = "" dim objliteralcontrol as literalcontrol dim intspan as integer = 1 dim objdatagriditemtospan as datagriditem dim i, j as integer dim strtemp as string for i = 0 to datagrid1.items.count - 1 intspan = 1 objliteralcontrol = ctype(datagrid1.items(i).cells(intcell).controls(0), literalcontrol) strcell1 = objliteralcontrol.text
for j = i + 1 to datagrid1.items.count - 1 objliteralcontrol = ctype(datagrid1.items(j).cells(intcell).controls(0), literalcontrol) strcell2 = objliteralcontrol.text if strcell1 = strcell2 then intspan += 1 datagrid1.items(i).cells(intcell).rowspan = intspan datagrid1.items(j).cells(intcell).visible = false else exit for end if next i = j - 1 next
end sub 除了設定rowspan 外,還要把下面行的visible 設成false,否則不起作用,底下會多出一個column.這個datagrid的每個cell中都包含一個literalcontrol,如果沒有的話,就直接用datagrid1.items(i).cells(intcell).text即可.參數intcell ,是指要合併的那個列.