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 }
用途:可以設那一些使用者可以訪問哪一些許可權。