Click here to Skip to main content
15,915,164 members
Home / Discussions / C#
   

C#

 
GeneralExcel Automation Questions Pin
Guinness4Strength22-Dec-04 4:18
Guinness4Strength22-Dec-04 4:18 
Questionocx or socketcommunication? Pin
stefan houtz22-Dec-04 4:08
stefan houtz22-Dec-04 4:08 
Generaldynamic assigning of class properties Pin
TyronX22-Dec-04 2:51
TyronX22-Dec-04 2:51 
GeneralRe: dynamic assigning of class properties Pin
J4amieC22-Dec-04 3:48
J4amieC22-Dec-04 3:48 
GeneralRe: dynamic assigning of class properties Pin
Skynyrd22-Dec-04 3:48
Skynyrd22-Dec-04 3:48 
GeneralRe: dynamic assigning of class properties Pin
TyronX22-Dec-04 10:43
TyronX22-Dec-04 10:43 
Generalget row number after datagrid sort Pin
jagberg2322-Dec-04 2:15
jagberg2322-Dec-04 2:15 
GeneralRe: get row number after datagrid sort Pin
aplope23-Dec-04 5:44
aplope23-Dec-04 5:44 
There are two different methods that can be used to do this. (Please be sure to check MSDN on the datagrid to get more details about both).

I color the column (not a row) that has just been sorted in an "OnItemCreated" procedure. I check to make sure the item is an Item or an Alternating Item and then I get the back color like this:

e.Item.Cells[m_iSortColumnIdx].BackColor = (System.Drawing.Color) new ColorConverter().ConvertFromString("#CCFFCC");


The other procedure you can use is the "OnItemDatabound" procedure. Again, you have to check to make sure the item is an Item or an Alternating Item.

From this method, you can access each of the cells and a number of attributes for that cell: text, back color, fore color, alignment, columnspan, class, etc. So if you know the column number (zero-based), you can also get the text.

Here's how I format my social security numbers in my very first column of my datagrid.

e.Item.Cells[0].Text = Utils.FormatSocial( (string)DataBinder.Eval(e.Item.DataItem, "social_num") );


I believe if you wanted to color the whole row, you might need to loop through each of the cells and set the color in the loop. (From what I remember of trying to do this in the past, this is how I had to change the style class or the color for an entire row).

You might also try 4 Guys From Rolla which is running an EXTENSIVE examination of the datagrid. You might find some discussion of these methods in that set of articles. The latest is # 17.

Pegmeister
GeneralRe: get row number after datagrid sort Pin
jagberg2324-Dec-04 20:18
jagberg2324-Dec-04 20:18 
GeneralDesigning a data decisional application based-on grids and graphics Pin
guim722-Dec-04 2:09
guim722-Dec-04 2:09 
GeneralServiceController.WaitForStatus() method query Pin
ipsoftware22-Dec-04 2:06
ipsoftware22-Dec-04 2:06 
GeneralRe: ServiceController.WaitForStatus() method query Pin
Dave Kreskowiak22-Dec-04 6:17
mveDave Kreskowiak22-Dec-04 6:17 
GeneralTextBox caret jump Pin
Aviv Halperin22-Dec-04 1:18
Aviv Halperin22-Dec-04 1:18 
Generalon prepared statement in sql Pin
ting66822-Dec-04 0:11
ting66822-Dec-04 0:11 
GeneralRe: on prepared statement in sql Pin
David Salter22-Dec-04 0:24
David Salter22-Dec-04 0:24 
Generalhelp me shut dow xp white c# cod Pin
mehdidj21-Dec-04 20:56
mehdidj21-Dec-04 20:56 
GeneralRe: help me shut dow xp white c# cod Pin
J4amieC21-Dec-04 22:35
J4amieC21-Dec-04 22:35 
GeneralRe: help me shut dow xp white c# cod Pin
benjymous21-Dec-04 23:38
benjymous21-Dec-04 23:38 
GeneralRe: help me shut dow xp white c# cod Pin
Judah Gabriel Himango22-Dec-04 6:43
sponsorJudah Gabriel Himango22-Dec-04 6:43 
GeneralRe: help me shut dow xp white c# cod Pin
Matt Gerrans22-Dec-04 12:48
Matt Gerrans22-Dec-04 12:48 
GeneralI tried to set labe control property visible to true Pin
Mohammed Aijaz Mohiuddin21-Dec-04 19:23
Mohammed Aijaz Mohiuddin21-Dec-04 19:23 
GeneralRe: I tried to set labe control property visible to true Pin
Skynyrd21-Dec-04 22:32
Skynyrd21-Dec-04 22:32 
GeneralRe: I tried to set labe control property visible to true Pin
Mohammed Aijaz Mohiuddin23-Dec-04 1:08
Mohammed Aijaz Mohiuddin23-Dec-04 1:08 
GeneralRe: I tried to set labe control property visible to true Pin
Skynyrd23-Dec-04 5:36
Skynyrd23-Dec-04 5:36 
GeneralGetArray and SetArray Pin
SudeepPradhan21-Dec-04 18:30
SudeepPradhan21-Dec-04 18:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.