Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Cell style gets lost when sorting a datagridview

$
0
0

I have a datagridview which the user can check off and every row that gets checked of that row's back color changes to yellow. When the user sorts the datagridview then any row that was yellow loses it's background color and reverts back to the original back color. How can I change that so the user can sort with out losing it's yellow back color. 

Also, I'm trying to handle that when the user tries checking off the checkbox column and the criteria for checking off were not met a message box should pop up and say that the box can't be checked off. Below is the code to do this.

private void dgv_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)

{

if(e.ColumnIndex == 0 && e.RowIndex > -1 && (bool)dgv.Rows[0].FormattedVaue == false)

{

if(criteria......)

{

e.cancel = true

MessageBox.Show("Can't check off row.");

}

}

}

The problem is that the header columns all have the column and row index of 0 so when I try sorting the columns if the first check box can't be checked off this message box will pop up. Is there anything that can be done about this problem?


Debra has a question


Viewing all articles
Browse latest Browse all 2535

Trending Articles