473,397 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

c# highlight certain rows

AaronW
4
I am trying to do conditional formatting of rows in a datagrid and can not get DataGridItemEventArgs as an option. Is there something wrong with the assembly?

using System;
using System.Drawing;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using System.Data;
using System.Timers;
Nov 8 '07 #1
6 2025
Plater
7,872 Expert 4TB
That is not much to go on.
Are you sure you're not looking at descriptions for DataGridView and not DataGrid?
Nov 8 '07 #2
AaronW
4
I am trying to loop through the datagrid and once I find a cell with certain information I would like to highlight the entire row.
--------------------------------------------------------------
private void BindUsers()
{
Domain = cboDomain.SelectedValue.ToString();
OU = cboOU.SelectedValue.ToString();
SiteCode = cboSite.SelectedValue.ToString();

DataSet ds = dsVendors(Domain, OU, SiteCode);
DataTable dt = ds.Tables["Vendors"];
dgMain.DataSource = dt;
dgMain.AlternatingBackColor = Color.LightSteelBlue;

// set the number of users
intNumUsers = dt.Rows.Count;

// finally compute our randomization
ComputeRandomMetrics();
}
--------------------------------------------------------------

I tried the following with the dataset but recieved sereval errors and figured I would be better off looping through the grid once the data is loaded.

private void DataGridView1_CellFormatting(object sender, System.Windows.Forms.DataGridViewCellFormattingEve ntArgs e)
{
DataRowView drv;
if (e.RowIndex >= 0) {
if (e.RowIndex <= ds.Tables("Vendors").Rows.Count - 1) {
drv = ds.Tables("Vendors").DefaultView.Item(e.RowIndex);
Color c;
if (drv.Item("location").ToString == "ACTION REQUIRED") {
c = Color.Red;
}
else {
c = Color.Black;
}
e.CellStyle.BackColor = c;
}
}
}
Nov 9 '07 #3
Plater
7,872 Expert 4TB
by higlight do you mean "select" or change the visible colors of?
Nov 9 '07 #4
AaronW
4
I would prefer to change the background color if possible.
Nov 13 '07 #5
Plater
7,872 Expert 4TB
Can't you set that on DataGridViewRow object?
Nov 13 '07 #6
AaronW
4
Got it with:

private void AddCellFormattingColumnStyles(DataGrid grid, FormatCellEventHandler handler)
{
DataGridTableStyle ts = new DataGridTableStyle();
DataTable dt = (DataTable) grid.DataSource;
ts.MappingName = dt.TableName;

for(int j = 0; j < dt.Columns.Count; ++j)
{
DataGridFormattableTextBoxColumn cs = new DataGridFormattableTextBoxColumn(j);
cs.MappingName = dt.Columns[j].ColumnName;
cs.HeaderText = dt.Columns[j].ColumnName;
cs.SetCellFormat += handler;
ts.GridColumnStyles.Add(cs);
}

//grid.TableStyles.Clear();
grid.TableStyles.Add(ts);

}

private void FormatGridCells(object sender, DataGridFormatCellEventArgs e)
{
CurrencyManager cm = (CurrencyManager)this.BindingContext[this.dgMain.DataSource];

object cellValue = this.dgMain[e.Row, 4];
if (cellValue.ToString() == "ACTION REQUIRED")
{
e.BackBrush = Brushes.Red;
}
}
Nov 14 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: john woo | last post by:
Hi I'm not good at JS, but want to get more about it. I want to use a JSP (the java code just used to get date, the rest are html and javascript), to display a table. the requirement is the...
2
by: Steve K | last post by:
Firstly, how the heck does this guy do it? Writing reams of (awesome) code, debugging, responding to Newsgroups etc., all while commanding the ridiculous price of FREE?!?!?! More power to him! ...
2
by: Sridhar | last post by:
Hi, I have a datagrid which contains 3 columns. Two of them are Bound Column types and the third one is Button Column. When I click on one of the rows in that Button Column, I would like to...
17
by: toffee | last post by:
Hi all, I have a table with 12 cols and 10 rows. When a user clicks on a table cell; the page is refreshed and displays some data below the table dependant on whichever cell was selected. I...
3
by: tirath | last post by:
hi, I have a DataView which has around 50 items(the page has scrollbars). there is a search box on top of the page. when user enters an Id, i do DataView.find("Id"). I get the row index but i...
3
by: almurph | last post by:
Hi, I'm a newbie to Javascript. I can;t even finf a full API for it! Anyway I have a table structure and when a user presses the down-arrow button the item in said table is meant to be...
3
by: ago | last post by:
Hi, I have an access query that finds the rows that have certain parameters common among them eg : Username How is it possible to highlight the matches or display only the matches. TBL:...
2
by: -Steve- | last post by:
I have the need to change the text of certain rows to red based on the proximity of a date in one of the columns. What's the best way to go about this?
3
sujathaeeshan
by: sujathaeeshan | last post by:
Hello all, I want to highlight or select data grid row based on first letter of first column in data grid with keyboard. Just by pressing the key of first letter of the column ,it has to...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.