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

为什么,我的DevExpress.XtraGrid.GridControl不能显示数据呢?
为什么,我的DevExpress.XtraGrid.GridControl不能显示数据呢?
//  
//   gridControl1
//  
this.gridControl1.Dock   =   System.Windows.Forms.DockStyle.Fill;
//  
//   gridControl1.EmbeddedNavigator
//  
this.gridControl1.EmbeddedNavigator.Name   =   " ";
this.gridControl1.Location   =   new   System.Drawing.Point(3,   17);
this.gridControl1.MainView   =   this.gridView1;
this.gridControl1.Name   =   "gridControl1 ";
this.gridControl1.Size   =   new   System.Drawing.Size(650,   404);
this.gridControl1.TabIndex   =   1;
this.gridControl1.ViewCollection.AddRange(new   DevExpress.XtraGrid.Views.Base.BaseView[]   {
this.gridView1});
//  
//   gridView1
//  
this.gridView1.GridControl   =   this.gridControl1;
this.gridView1.Name   =   "gridView1 ";
//  
//   tbTools
//  
this.tbTools.Buttons.AddRange(new   System.Windows.Forms.ToolBarButton[]   {
      this.tbbDelete,
      this.tbbSave,
      this.tbbSeparator1,
      this.tbbExit});
this.tbTools.DropDownArrows   =   true;
this.tbTools.Location   =   new   System.Drawing.Point(0,   0);
this.tbTools.Name   =   "tbTools ";
this.tbTools.ShowToolTips   =   true;
this.tbTools.Size   =   new   System.Drawing.Size(656,   41);
this.tbTools.TabIndex   =   43;
//  
//   gridView1
//  
this.gridView1.Columns.AddRange(new   DevExpress.XtraGrid.Columns.GridColumn[]   {
  this.colsendCoID,
  this.colsendCoName,
  this.colsendCoAdd,
  this.colsendPostCode});
this.gridControl1.DataSource   =   DbHelperSQL.Query( "SELECT   id,   sendCoID,   sendCoName,   sendCoAdd,   sendPostCode   FROM   sendCoInfor ").Tables[0];
this.gridControl1.UseEmbeddedNavigator=true;


------解决方案--------------------
你通过Run Designer建立那些列,并且排布了没有

------解决方案--------------------
this.gridControl1.DataSource = DbHelperSQL.Query( "SELECT id, sendCoID, sendCoName, sendCoAdd, sendPostCode FROM sendCoInfor ").Tables[0];
这句只是将数据表绑定到了Grid,但并没有告诉Grid该怎么显示.其实你只要在这句后面加this.gridView1.PopulateColumns();就可以了,这句可以理解为把数据表中的所有列都显示出来.
还有,不是很明白你所说的保存编辑内容是什么意思?
如果是要将修改保存到数据表,用gridView1.UpdateCurrentRow();
如果要保存到数据库,那就要另外写更新语句了.