Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
2.60/5 (2 votes)
See more:
i have no idea ho to do?please help me..

For Ex:


see this link A DataGridView Column Show/Hide Popup[^]


In this link the context menu appeared by rightclick event, But i want to show that column selection in checkbox list without rightclick

Ex:http://www.dotnetspark.com/kb/1875-show-hide-datagrid-columns-wpf.aspx[^]

i need2nd link method
Posted
Updated 7-Sep-15 1:21am
v2
Comments
Thava Rajan 18-Sep-15 0:22am    
the solutions is already in that link?,
what would you expect, please clarify it

1 solution

To do this you have to add the GridView_RowDataBound event to the datagrid.
You will have to create a list to store the selected indexes from the checkbox list, let's call it checkedColumnsList [List<int>].

The GridView_RowDataBound must look like the code below
C#
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{   
    e.Row.Cells[index].Visible = checkedColumnsList.Contains(index)? true : false; 
}


Note that every time user checks or unchecks the visibility you have to Bind the gridview again in order to trigger the GridView_RowDataBound event again and thus change the visibility.
 
Share this answer
 
v2

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