GridViewSetterBase.cs 903 B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Forms;
  7. namespace PTMedicalInsurance.FormSetter
  8. {
  9. public class GridViewSetterBase
  10. {
  11. /// <summary>
  12. /// 动态增加datagridview列
  13. /// </summary>
  14. /// <param name="dgv"></param>
  15. /// <param name="headerText"></param>
  16. /// <param name="dataPropertyName"></param>
  17. protected void AddDGVColumn(DataGridView dgv, string headerText, string dataPropertyName, int width = 120)
  18. {
  19. DataGridViewColumn newColumn = new DataGridViewTextBoxColumn();
  20. newColumn.HeaderText = headerText;
  21. newColumn.Width = width;
  22. newColumn.DataPropertyName = dataPropertyName;
  23. newColumn.Name = dataPropertyName;
  24. dgv.Columns.Add(newColumn);
  25. }
  26. }
  27. }