Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have dataset, which has 7 columns,
i have a datagrid, binded to above dataset,i have a boolean column,whose columnstyle is datagridviewcheckbox style, i want to set it to
datagridviewtextboxcolumn style,

so that when boolean values are displayed in datagrid, instead of checkbox,i want true/false text to be written as column values.

DataSet ds = daoDistrict.FillDistrictGrid(Convert.ToInt32(cbStateName.SelectedValue));
dgDistrict.DataSource = ds.Tables[0];                        

DataGridViewTextBoxColumn txtBxCol = new DataGridViewTextBoxColumn();
            DataGridViewColumn tempCol = (DataGridViewColumn)dgDistrict.Columns[6];
            txtBxCol = (DataGridViewTextBoxColumn)tempCol;            
            txtBxCol.Name = "IsActive";
            txtBxCol.DataPropertyName = "IsActive";
            txtBxCol.HeaderText = "Is--Active";
            DataGridView dgv = txtBxCol.DataGridView;            
            bool val = txtBxCol.Displayed;
            int ind = txtBxCol.DisplayIndex;
            bool isDat = txtBxCol.IsDataBound;
            txtBxCol.ValueType = txtBxCol.GetType(); 


above code throws cast exception, unable to cast DGVCheckbxcol to DGVtextbxcol

thanks in advance
Posted

1 solution

unable to cast DGVCheckbxcol to DGVtextbxcol


this can be never casted, DataGridViewTextBoxColumn is deferent from DataGridViewCheckBoxColumn

try

DataGridViewCheckBoxColumn txtBxCol = new DataGridViewCheckBoxColumn();
            DataGridViewColumn tempCol = (DataGridViewColumn)dgDistrict.Columns[6];
            txtBxCol = (DataGridViewCheckBoxColumn)tempCol; 
 
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