frmExcelViewer.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace wispro.sp.winform
  11. {
  12. public partial class frmExcelViewer : Form
  13. {
  14. public frmExcelViewer()
  15. {
  16. InitializeComponent();
  17. }
  18. private DataTable _data;
  19. public DataTable Data {
  20. get {
  21. return _data;
  22. }
  23. set
  24. {
  25. _data = value ;
  26. if(_data != null)
  27. {
  28. dataGridView1.DataSource = _data;
  29. }
  30. }
  31. }
  32. private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
  33. {
  34. Rectangle rect = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y,
  35. dataGridView1.RowHeadersWidth - 4, e.RowBounds.Height);
  36. TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
  37. dataGridView1.RowHeadersDefaultCellStyle.Font, rect,
  38. dataGridView1.RowHeadersDefaultCellStyle.ForeColor,
  39. TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
  40. }
  41. }
  42. }