为了让数据显示在行内,也为熟练一下devexpress treelist 控件, 查找了很多,最多的是先把数据放在datatable 表里边, 然后赋值给treelist的datasource 的方式
因为我的数据就是一列或者两列没有子节点.所以这种方式感觉有些麻烦
最终用append 方式赋值.
public static void ShowOnTreeList(TreeList control, string mess)
{
if (control.InvokeRequired)
{
control.BeginInvoke(new MethodInvoker(delegate
{
control.AppendNode(new object[] { mess }, null);
// control.Items.Add(mess);
//control.AppendText(mess + "
");
}));
}
else
{
control.AppendNode(new object[] { mess }, null);
}
}
顺便把显示行号的方法放在这
private void tlhand_CustomDrawNodeIndicator(object sender, DevExpress.XtraTreeList.CustomDrawNodeIndicatorEventArgs e)
{
TreeList tree = sender as DevExpress.XtraTreeList.TreeList;
tree.IndicatorWidth = 30;
IndicatorObjectInfoArgs args = e.ObjectArgs as IndicatorObjectInfoArgs;
args.DisplayText = (tree.GetVisibleIndexByNode(e.Node) + 1).ToString();
}