how i can disable and enabled based on a single dataGridview cell color

Asked By six fourty
09-Feb-10 12:07 PM
Earn up to 0 extra points for answering this tough question.
hi,Guy's
How i can disable and enabled based on a single dataGridview cell color here is the code that i try

private void time_out_Click(object sender, EventArgs e)
        {
            DataGridView.SelectedCells[0].Style.ForeColor = Color.Red;
            if (GridView.SelectedCells[0].Style.ForeColor==Color.Red)
            {
                time_in.Enabled = true;
            }
           
               time_out.Enabled = false;
 i want to do is when the text color is red in the dataGridview the time in button is enabled and not the other for a single cell not for the all cell.pls Guy's help me what to do. 
            

  re: how i can disable and enabled based on a single dataGridview cell color

Web Star replied to six fourty
09-Feb-10 12:20 PM
u can disable and enable a button in girdview in rowbound event
  1. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  2. {
  3.      if (e.Row.RowType == DataControlRowType.DataRow)
  4.      {
  5.          //u can check your addition condition here for color of cell or any thing else
  6.              e.Row.Cells[3].FindControls["timein"].Enabled = flase;
  7.       }
  8.      }
  9. }

  Assuming time_in button is outside the GridView:

[)ia6l0 iii replied to six fourty
09-Feb-10 03:11 PM
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
  if (e.Row.RowType == DataControlRowType.DataRow)  && (e.Row.Cells[1].Style.ForeColor==Color.Red))
  { 
time_in.Enabled = true;
  }
 else
 {
time_in.Enabled = true;
 }
}

Hope that helps

  re: how i can disable and enabled based on a single dataGridview cell color

Huggy Bear replied to six fourty
10-Feb-10 12:06 AM

I am going with windows forms datagridview, since your question states datagridview and you question is posted under C#.Net category.
Check the below single line of code, I am not sure why you were using the SelectedCells and your requirement was nothing to do with the selected cells.

time_in.Enabled = (dataGridView1.Rows[0].Cells[0].Style.ForeColor == Color.Red);

  re: re: how i can disable and enabled based on a single dataGridview cell color
six fourty replied to Huggy Bear
10-Feb-10 01:45 PM

   hello Guy's i try all suggestions still all the codes are not work. to make my Q clear .........
 
   i use two buttons  out side of the dataGridview  to change the color of each cell in the dataGridview from red to green and Green to red to do this

private void time_in_Click(object sender, EventArgs e)
        {
            employee_InformationDataGridView.SelectedCells[0].Style.ForeColor = Color.Green;
   
        }
private void time_out_Click(object sender, EventArgs e)
        {
            employee_InformationDataGridView.SelectedCells[0].Style.ForeColor = Color.Red;
            }
now i want to enable and disable my two Button based on the color and for each selected cell i mean when the text is red in the dataGridview time_in button only enable if it is green button time_out  is only enable. 
  re: re: re: how i can disable and enabled based on a single dataGridview cell color
Huggy Bear replied to six fourty
11-Feb-10 02:51 AM
Here is the code
private void time_in_Click(object sender, EventArgs e)
{
    employee_InformationDataGridView.SelectedCells[0].Style.ForeColor = Color.Green;
    //simply disable time_in after setting the color to green and enable time_out
    time_in.Enabled = false;
    time_out.Enabled = true;
private void time_out_Click(object sender, EventArgs e)
{
    employee_InformationDataGridView.SelectedCells[0].Style.ForeColor = Color.Red;
    //simply disable time_out after setting the color to red and enable time_in
    time_in.Enabled = true;
    time_out.Enabled = false;
}
  re: re: re: re: how i can disable and enabled based on a single dataGridview cell color
six fourty replied to Huggy Bear
11-Feb-10 04:56 AM
i try this code also it is not working for the first cells only. it is not work as i want it.
 for the first cell  it change the font color and time_in button become disable and enable time_out 
then it will be remain when i go to the next cell. 
  re: re: re: re: re: how i can disable and enabled based on a single dataGridview cell color
Huggy Bear replied to six fourty
11-Feb-10 05:20 AM
Make your question/requirement/issue clear while posting it. So that it would be easy for us to help you.
In the SelectionChanged event of the datagridview enable both the buttons (remove the colours if you want).
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
    //enable both the buttons
    time_in.Enabled = true;
    time_out.Enabled = true;
}
Create New Account