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

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
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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This article will show, step by step, how to integrate R code into a R Sweave document
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

860 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