/// <summary>
/// DataGrid相邻行有相同内容时对指定列合并
/// </summary>
/// <param name="spangrid">格式化的DataGrid的ID</param>
/// <param name="spancell">要合并的列</param>
/// <param name="spanby">合并所依据数据的列</param>
public void FormatGrid(DataGrid spangrid,int spancell,int spanby)
{
if(spanby<0 || spanby>spangrid.Items.Count)
return;
int rowspan = 1;
for(int i = 1;i<spangrid.Items.Count;i++)
{
if(spangrid.Items[i].Cells[spanby].Text == spangrid.Items[i-1].Cells[spanby].Text)
{
rowspan +=1;
spangrid.Items[i].Cells[spancell].Visible = false;
spangrid.Items[i-rowspan+1].Cells[spancell].RowSpan = rowspan;
}
else
{
string str = spangrid.Items[i].Cells[spanby].Text;
string str1 = spangrid.Items[i-1].Cells[spanby].Text;
rowspan = 1;
}
}
}
C#可以实现DLL库的动态调用/// DataGrid相邻行有相同内容时对指定列合并
/// </summary>
/// <param name="spangrid">格式化的DataGrid的ID</param>
/// <param name="spancell">要合并的列</param>
/// <param name="spanby">合并所依据数据的列</param>
public void FormatGrid(DataGrid spangrid,int spancell,int spanby)
{
if(spanby<0 || spanby>spangrid.Items.Count)
return;
int rowspan = 1;
for(int i = 1;i<spangrid.Items.Count;i++)
{
if(spangrid.Items[i].Cells[spanby].Text == spangrid.Items[i-1].Cells[spanby].Text)
{
rowspan +=1;
spangrid.Items[i].Cells[spancell].Visible = false;
spangrid.Items[i-rowspan+1].Cells[spancell].RowSpan = rowspan;
}
else
{
string str = spangrid.Items[i].Cells[spanby].Text;
string str1 = spangrid.Items[i-1].Cells[spanby].Text;
rowspan = 1;
}
}
}
Assembly assmebly = Assembly.LoadFile(@"C:WindowsApplication2005-09-30.dll");
Type t = assmebly.GetType("WindowsApplication2005_09_30.Class1");
object obj = Activator.CreateInstance(t,null);
MethodInfo method = t.GetMethod("Test01");
int i = (int)method.Invoke(obj,new object[1]{10});
namespace WindowsApplication2005_09_30
{
public class Class1
{
public int Test01(int i)
{
return i*10;
}
}
}
Type t = assmebly.GetType("WindowsApplication2005_09_30.Class1");
object obj = Activator.CreateInstance(t,null);
MethodInfo method = t.GetMethod("Test01");
int i = (int)method.Invoke(obj,new object[1]{10});
namespace WindowsApplication2005_09_30
{
public class Class1
{
public int Test01(int i)
{
return i*10;
}
}
}