Solved

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

Posted on 2008-10-29
2
480 Views
Last Modified: 2013-12-17
Hi

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

                myDsFilesToUndo.Merge(importedReconsiledfiles);

                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

0
Comment
Question by:Adnan
2 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
Comment Utility
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

Next
 

End If

End If

End Sub

Open in new window

0
 

Author Closing Comment

by:Adnan
Comment Utility
nice ;)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This video teaches viewers about errors in exception handling.
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.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now