Results 1 to 8 of 8

Thread: [RESOLVED] Change Cell Color + GridView

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Resolved [RESOLVED] Change Cell Color + GridView

    I want to change the value & its backcolor of cell.
    On Button1_Click,I m adding records to the Gridview.
    On Button3_Click,I want to chnage the value of cell & its backcolor.

    Suppose two Rows & two columns are there in Grdiview
    1 10
    2 20

    Suppose I want to change the value of item(Row=2,Colomn=2) to 100. I change the value but i m not ablt to change the backcolor.Can somebody tell me?


    Code:
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
    
                Dim row0 As String() = {TextBox1.Text, TextBox2.Text}
                DataGridView1.Rows.Add(row0)
                row0 = Nothing
    
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Sub
    
    
     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Try
    
                DataGridView1.Item(1, 1).Value = 100
               'What to write to chnage the cell color
    
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Sub

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Change Cell Color + GridView

    Code:
    dataGridView1.Rows[0].Cells[0].Style.BackColor = Color.Red;
    Please mark you thread resolved using the Thread Tools as shown

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Re: [RESOLVED] Change Cell Color + GridView

    Thanks very much

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Re: [RESOLVED] Change Cell Color + GridView

    Tell me one thing more that is it possible to change all colors of row of Griview widout using any for loop( For RowNum = 0 To DataGridView1.RowCount - 2)

  5. #5
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [RESOLVED] Change Cell Color + GridView

    Are you looking for this one ?

    Code:
    dataGridView1.Rows[0].DefaultCellStyle.BackColor = Color.Red;
    Please mark you thread resolved using the Thread Tools as shown

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Re: [RESOLVED] Change Cell Color + GridView

    Suppose there are 10 rows in Gridview,Is it poss to chnage all the 10 rows backcolor at once,Without uisng any Gridview Row loop

  7. #7
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [RESOLVED] Change Cell Color + GridView

    Here it is

    Code:
    dataGridView1.DefaultCellStyle.BackColor = Color.Red;
    Please mark you thread resolved using the Thread Tools as shown

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Re: [RESOLVED] Change Cell Color + GridView

    Thx thx very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width