Results 1 to 5 of 5

Thread: [2.0] Saving changes to a datagridview - colour the rows

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    [2.0] Saving changes to a datagridview - colour the rows

    Hello,

    [VS 2005]

    I am using typed datasets. I have 2 datagridView and when I click one GridA it will add a row to GridB. This works fine and the data is saved to the database.

    However, the customer wants to add the rows to GridB and save periodically.

    I am wondering is there a way to show the rows that have not been saved, and when the user clicks the save button it will change them to a different colour.

    So it will commit some rows everytime the user clicks save. The user can add some more rows and they will be displayed in blue. Once the user clicks save all the rows that have just been added will be saved to the database and then change colour to green.

    Can anyone point me in the right direction or give me some code example, will be most grateful.

    Many thanks,

    Steve
    steve

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Saving changes to a datagridview - colour the rows

    This is untested but it would be something like handling the CellValidated event and implementing the following:
    vb Code:
    1. Dim gridRow As DataGridViewRow = myGrid.Rows(e.RowIndex)
    2. Dim tableRow As DataRow = DirectCast(gridRow.DataBoundItem, DataRowView).Row
    3.  
    4. If tableRow.RowState = DataRowState.Unchanged Then
    5.     gridRow.DefaultCellStyle.BackColor = Color.Green
    6. Else
    7.     gridRow.DefaultCellStyle.BackColor = Color.Blue
    8. End If
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Saving changes to a datagridview - colour the rows

    Bah! Forgot I was in C# land. You've posted in VB.NET so I'll assume that you can perform the conversion.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: [2.0] Saving changes to a datagridview - colour the rows

    JM, I just want to ask if DirectCast method can be use in C#? is there anything i need to reference to? Thanks in advance!

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Saving changes to a datagridview - colour the rows

    Quote Originally Posted by daimous
    JM, I just want to ask if DirectCast method can be use in C#? is there anything i need to reference to? Thanks in advance!
    This:
    vb.net Code:
    1. Dim var As SomeType = DirectCast(obj, SomeType)
    is equivalent to this:
    C# Code:
    1. SomeType var = (SomeType)obj;
    This:
    vb.net Code:
    1. Dim var As SomeType = TryCast(obj, SomeType)
    is equivalent to this:
    C# Code:
    1. SomeType var = obj as SomeType;
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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