1.小窗口如图所示
相应的后台代码:
View Code
1 public partial class HideColumn : Form 2 { 3 public DataGridView dgv { set ; get ; } 4 5 public HideColumn() 6 { 7 InitializeComponent(); 8 } 9 10 private void btnHideColumn_Click( object sender, EventArgs e) 11 { 12 dgv.Columns[ 3 ].Visible = false ; 13 } 14 }
2.在含有datagridview的窗口
当单击ShowHideColumn时,执行的操作代码如下:
View Code
1 private void showHideToolStripMenuItem_MouseDown( object sender, MouseEventArgs e) 2 { 3 HideColumn hc = new HideColumn(); 4 hc.dgv = dataGridView1; 5 hc.Visible = true ; 6 7 }
弹出的窗口具有模式对话框的代码如下:
View Code
1 private void showHideToolStripMenuItem_MouseDown( object sender, MouseEventArgs e) 2 { 3 HideColumn hc = new HideColumn(); 4 hc.dgv = dataGridView1; 5 hc.ShowDialog(); 6 7 }
2.冻结窗口的代码如下。代码出现在小窗口中
代码如下:
View Code
1 private void btnSure_Click( object sender, EventArgs e) 2 { 3 int rowNum = Convert.ToInt32(tbRowNum.Text); 4 int columnNum = Convert.ToInt32(tbColumnNum.Text); 5 if (rowNum >= 0 && rowNum < dgv.Rows.Count) 6 { 7 dgv.Rows[rowNum].Frozen = true ; 8 9 } 10 if (columnNum >= 0 && columnNum < dgv.Columns.Count) 11 { 12 dgv.Columns[columnNum].Frozen = true ; 13 } 14 }
用途:可以设那一些用户可以访问哪一些权限。