c# WinForm 编程总结

1、清空DataGridView

 1 /// <summary>

 2         /// 清空DataGridView

 3         /// </summary>

 4         /// <param name="dg">DataGridView</param>

 5         public void ClearDataGridView(DataGridView dg)

 6         {

 7             try

 8             {

 9                 if (dg == null || dg.DataSource == null)

10                 {

11                     return;

12                 }

13 

14                 DataTable dt = (DataTable)dg.DataSource;

15 

16                 dt.Rows.Clear();

17 

18                 dg.DataSource = dt;

19 

20             }

21             catch (Exception e)

22             {

23                 string errorMsg = string.Format(@"清除{0} DataGridView数据时出错,错误原因:{1}", dg.Name, e.Message);

24 

25                 Platform.Log(LogLevel.Fatal, errorMsg);

26 

27                 AlifMessageBoxShowError(errorMsg);

28             }

29         }

 2、清空C1FlexGrid

 1 /// <summary>

 2         /// 清空C1FlexGrid

 3         /// </summary>

 4         /// <param name="c1FG">C1FlexGrid</param>

 5         public void ClearC1FlexGrid(C1.Win.C1FlexGrid.C1FlexGrid c1FG)

 6         {

 7             try

 8             {

 9                 if (c1FG != null)

10                 {

11                     c1FG.Clear(C1.Win.C1FlexGrid.ClearFlags.Content);

12                 }

13             }

14             catch (Exception e)

15             {

16                 string errorMsg = string.Format(@"清空{0} C1.Win.C1FlexGrid.C1FlexGrid数据时出错,错误原因:{1}", c1FG.Name, e.Message);

17 

18                 Platform.Log(LogLevel.Fatal, errorMsg);

19 

20                 AlifMessageBoxShowError(errorMsg);

21             }

22         }

 

你可能感兴趣的:(WinForm)