Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
when i hid the particular column i don't want to hid the date and session in data grid view.


for that how to validate.


Hide button code as follows;

C#
if (MessageBox.Show("Are You sure, You want to Hide?", "Hide confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
           datagridView.Columns[datagridView.CurrentCellAddress.X].Visible = false;
            }


Output as follows; Hide(Button)

DATE SESSION RK Mk CK VB GS CMK UNNI

1//2013 1


in that when i click the hide button,in that column values is there that validation is working fine. no problem.


But i don't to hide the DATE and SESSION Column always in data grid view.

for that validation how to write the code.
Posted
Updated 14-Jan-13 23:42pm
v2

1 solution

C#
void HideButton_Click(object sender, EventArgs e)
{
    DataGridViewColumn column
        = datagridView.Columns[datagridView.CurrentCellAddress.X];
    if(
        column == _dateColumn
        || column == _sessionColumn
    )
    // Both mentioned columns shall not be hidden.
    {
        return;
    }

    if (MessageBox.Show("Are You sure, You want to Hide", "Hide confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
    {
        column.Visible = false;
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900