How to color Rows in a DataGridView with two dataset merged.....

Posted on 2008-10-29
Last Modified: 2013-12-17

I want to color my rows in datagridview, i want to color rows only 1 of the dataset not all og the rows, color only rows on one of the datasets....
if (chkReconsiled.Checked)
                btnUndoImport.Visible = false;
                lblcannotundo.Visible = true;
                lblcannotundo.Text = "Kan ikke oppheve avstemte import";
                gridImports.DataSource = myDsFilesToUndo.Tables[0];
                //importedReconsiledfiles.Tables[0].RowsDefaultCellStyle.BackColor = Color.AliceBlue;
                //gridImports.RowsDefaultCellStyle.BackColor = Color.AliceBlue;
                ////gridImports.DataSource = importedReconsiledfiles.Tables[0];
                //gridImports.RowsDefaultCellStyle.BackColor = Color.White;
                //gridImports.ReadOnly = true;
                //gridImports.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
                //gridImports.MultiSelect = false;
            if (!chkReconsiled.Checked)
                btnUndoImport.Visible = true;
                lblcannotundo.Visible = false;
                gridImports.DataSource = myDsFilesToUndo.Tables[0];
                gridImports.RowsDefaultCellStyle.BackColor = Color.White;
                gridImports.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

Open in new window

Question by:Adnan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 53

Accepted Solution

Dhaest earned 500 total points
ID: 22830840
Can you see from the data from which recordset the record comes ? I mean: is there a column which will tell us this comes from dataset1, this from 2

If so, you can check the following event
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
Dim intPrice As Decimal = e.Item.Cells(1).Text ' thsi is price column no.
If intPrice > 100 Then
Dim i As Int16
For i = 0 To DataGrid1.Columns.Count
e.Item.Cells(i).BackColor = System.Drawing.Color.Red ' the row is in color red
End If
End If
End Sub

Open in new window


Author Closing Comment

ID: 31511136
nice ;)

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Name Space error VS2015 1 36
PowerShell:  Column widths won't expand 3 49
WPF Select Items 3 25
.NET - find out if application is running on Windows 2012 server 3 35
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question