日期:2014-05-19  浏览次数:21088 次

小妹求救!利用DataTable数据在TreeView里显示。
我把现有的数据存放到两个DataTable表里(如下),

表名:CarTable
Num     CarID   GroupID       CarNum       CarMotorman
  1           1             1           京A3352             张三
  2           3             1           京B4321             李四
  3           4             3           京C7680             王五
  4           5             1           京F3360             李六

表名:   GroupTable
Num       GroupID       GroupName
  1             1               车辆一组
  2             3               车辆三组

我想把这些表里的数据按照车辆组来分类,显示在一个
TreeView里,如何显示。请各位师哥代码明示。

我想显示的格式如下:

车辆一组
        京A3352
        京B4321
        京F3360
车辆二组
        京C7680

小妹刚刚入门请多多指教!

------解决方案--------------------
/// <summary>
/// Form初始化
/// </summary>
private void FCArea_Load(object sender, EventArgs e)
{
try
{
FormatGridMultilanguage();
BaseNode = new TreeNode();
BaseNode.Text = ResourceFactory.GetMultilanguage( "AREA ");
BaseNode.Name = "0 ";
treeView1.Nodes.Add(BaseNode);
ErmsDB ermsdb = new ErmsDB( "ConnectionAlarm ");
dtSite = ermsdb.FetchTable( "TArea ");
dtnew = ermsdb.FetchTableFrame( "TArea ");
dtnew.Rows.Add();
if (dtSite.Rows.Count > 0)
{
AddTree(int.Parse(BaseNode.Name), BaseNode);
txtAreaID.Text = "0 ";
txtAreaName.Text = ResourceFactory.GetMultilanguage( "AREA ");
txtAreaDes.Text = " ";
txtPAreaID.Text = " ";
this.btnSave.Enabled = false;
this.ckBoxFix.Enabled = false;
this.dtpFixStartTime.Enabled = false;
this.dtpFixEndTime.Enabled = false;
}
this.addCToolStripMenuItem.Enabled = true;
this.updateToolStripMenuItem.Enabled = true;
this.removeToolStripMenuItem.Enabled = true;

}
catch (Exception ex)
{
new Exception(ex.Message);

LogEntry logDb = new LogEntry();
Dictionary <string, object> errorInfo = new Dictionary <string, object> ();
errorInfo.Add( "DateTime ", DateTime.Now);
errorInfo.Add( "Exception Message ", ex.Message);
errorInfo.Add( "Operation ", this.Text + ResourceFactory.GetMultilanguage( "ERRORINITIAL "));