C# DEV XtraGrid

知识点一 显示XtraGrid.GridView的滚动条

要点:设定ColumnAutoWith选项为false和ShowHorzLines选项为True

具体步骤:GridView的Main-->Views-->OptionsView-->ColumnAutoWith选项为false和ShowHorzLines选项为True

另外的方法,在要改的Designer.cs中,直接更改列宽

 知识点二 删除XtraGrid.GridView选中的行 ,使用this.GridViewSalesOrder.DeleteSelectedRows();

 1         /// <summary>
 2         /// 删除方法
 3         /// </summary>
 4         /// <param name="sender"></param>
 5         /// <param name="e"></param>
 6         void item_Click(object sender, EventArgs e)
 7         {
 8             //this.GridSalesOrder.cu
 9             int[] selectRow = this.GridViewSalesOrder.GetSelectedRows();
10 
11             if (selectRow.Length < 0)
12             {
13                 MessageBox.Show("请选择删除的行!");
14                 return;
15             }
16 
17             this.GridViewSalesOrder.DeleteSelectedRows();
18             //for (int i = 0; i < selectRow.Length; i++)
19             //{
20             //    dtTmpGoods.Rows[i].Delete();
21             //    dtTmpGoods.AcceptChanges();
22             //}
23             MessageBox.Show("删除成功!");
24             //把临时的数据表填充到商品列表中
25             GridSalesOrder.DataSource = dtTmpGoods;
26             CalculateSaleOrder();
27         }

 

知识点三 右键出现菜单。使用XtraGrid.GridView的PopupMenuShowing事件

 1        /// <summary>
 2         /// 右键菜单
 3         /// </summary>
 4         /// <param name="sender"></param>
 5         /// <param name="e"></param>
 6         private void GridViewSalesOrder_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e)
 7         {
 8             string strMenuId = this.Tag.ToString();
 9             DXMenuItem item = new DXMenuItem(" 删除");
10             item.Click += new EventHandler(item_Click);
11             if (e.Menu != null && e.MenuType == DevExpress.XtraGrid.Views.Grid.GridMenuType.Row)
12             {
13                 e.Menu.Items.Insert(0, item);
14             }
15         }
16 
17         /// <summary>
18         /// 删除方法
19         /// </summary>
20         /// <param name="sender"></param>
21         /// <param name="e"></param>
22         void item_Click(object sender, EventArgs e)
23         {
24             //this.GridSalesOrder.cu
25             int[] selectRow = this.GridViewSalesOrder.GetSelectedRows();
26 
27             if (selectRow.Length < 0)
28             {
29                 MessageBox.Show("请选择删除的行!");
30                 return;
31             }
32 
33             this.GridViewSalesOrder.DeleteSelectedRows();
34             //for (int i = 0; i < selectRow.Length; i++)
35             //{
36             //    dtTmpGoods.Rows[i].Delete();
37             //    dtTmpGoods.AcceptChanges();
38             //}
39             MessageBox.Show("删除成功!");
40             //把临时的数据表填充到商品列表中
41             GridSalesOrder.DataSource = dtTmpGoods;
42             CalculateSaleOrder();
43         }

 

知识点四  Grid中的列显示N位小数,本例子中显示4位

显示效果:

 

所需设定,在设计模式下,选中列-->外观这个属性

 

 

 

     

 

 

posted @ 2013-01-29 11:44  杨斌_济南  阅读(1435)  评论(0编辑  收藏  举报