Click here to Skip to main content
15,917,565 members
Home / Discussions / C#
   

C#

 
QuestionAmazon API and C# Pin
tonyonlinux2-Jul-10 10:16
tonyonlinux2-Jul-10 10:16 
AnswerRe: Amazon API and C# Pin
Abhinav S2-Jul-10 17:57
Abhinav S2-Jul-10 17:57 
GeneralRe: Amazon API and C# Pin
tonyonlinux2-Jul-10 18:39
tonyonlinux2-Jul-10 18:39 
QuestionChange Row background color based by cell value Pin
grmihel22-Jul-10 5:14
grmihel22-Jul-10 5:14 
AnswerRe: Change Row background color based by cell value Pin
Henry Minute2-Jul-10 7:07
Henry Minute2-Jul-10 7:07 
AnswerRe: Change Row background color based by cell value Pin
Henry Minute2-Jul-10 8:37
Henry Minute2-Jul-10 8:37 
GeneralRe: Change Row background color based by cell value [modified] Pin
grmihel25-Jul-10 0:43
grmihel25-Jul-10 0:43 
GeneralRe: Change Row background color based by cell value Pin
Henry Minute5-Jul-10 3:34
Henry Minute5-Jul-10 3:34 
At the moment I can not see any reason why your DatabindingComplete handler doesn't fire. I will continue to look at that though.

Even if that was working there are two lines in the code that you posted which are contradictory and may cause problems.

C#
grid.Columns[5].AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
<big>grid.Columns[5].ValueType = typeof(decimal);</big>


C#
datas[item.Kundetype.Type].Rows.Add(item.KundeNavn, tilmeldte, ikketilmeldt, særaftale, tilmeldte + ikketilmeldt, <big>procent.ToString("###")</big>);


In the first block you are setting the ValueType to Decimal and yet in the second you are filling it with a string procent.ToString("###"). This is incompatible.

It might be better to modify the last one to simply use the result of your percentage calculation and take care of the displayed data by using the CellFormatting event of the DataGridView

Like this:
C#
datas[item.Kundetype.Type].Rows.Add(item.KundeNavn, tilmeldte, ikketilmeldt, særaftale, tilmeldte + ikketilmeldt, procent);


with the CellFormatting handler something like this:
C#
private void grid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    // Don't format if cell is null
    if ((e.Value == DBNull.Value) || (e.Value == null))
    {
        return;
    }

    // If it is the 'nummer6' column
    if (this.dataGridView1.Columns[e.ColumnIndex].Name == "nummer6")
    {
        // Format data source value and concatenate with " %"
        string nummer6Format = e.Value.ToString("###") + " %";

        // Set the display value
        e.Value = unitPriceFormat;

        // Signal that we've Formatted this value
        e.FormattingApplied = true;    //<============================ Very important
    }
}


This way you get to keep a numeric value in the DataGridViewCell/Column, much easier to deal with for comparisons, whilst displaying a prettified version, much easier for humans to deal with.

If the DataFormattingComplete ever works you can then use your
C#
if ((<big>decimal</big>)cell.Value < 70)   //<============== Note decimal cast NOT int
{
    row.DefaultCellStyle.BackColor = Color.LightPink;
}

with more confidence.
Henry Minute

Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas? - Because 31 Oct = 25 Dec.
Business Myths of the Geek #4 'What you think matters.'

GeneralRe: Change Row background color based by cell value Pin
grmihel26-Jul-10 3:27
grmihel26-Jul-10 3:27 
QuestionI want a Clever Text Display Pin
Nagy Vilmos2-Jul-10 5:03
professionalNagy Vilmos2-Jul-10 5:03 
AnswerRe: I want a Clever Text Display Pin
R. Giskard Reventlov2-Jul-10 5:12
R. Giskard Reventlov2-Jul-10 5:12 
AnswerRe: I want a Clever Text Display Pin
OriginalGriff2-Jul-10 5:32
mveOriginalGriff2-Jul-10 5:32 
GeneralRe: I want a Clever Text Display Pin
Nagy Vilmos2-Jul-10 5:46
professionalNagy Vilmos2-Jul-10 5:46 
AnswerRe: I want a Clever Text Display Pin
OriginalGriff2-Jul-10 5:33
mveOriginalGriff2-Jul-10 5:33 
GeneralRe: I want a Clever Text Display Pin
Nagy Vilmos2-Jul-10 5:47
professionalNagy Vilmos2-Jul-10 5:47 
GeneralRe: I want a Clever Text Display Pin
OriginalGriff2-Jul-10 5:54
mveOriginalGriff2-Jul-10 5:54 
GeneralRe: I want a Clever Text Display Pin
Nagy Vilmos2-Jul-10 7:14
professionalNagy Vilmos2-Jul-10 7:14 
AnswerRe: I want a Clever Text Display Pin
Luc Pattyn2-Jul-10 7:03
sitebuilderLuc Pattyn2-Jul-10 7:03 
GeneralRe: I want a Clever Text Display Pin
Nagy Vilmos2-Jul-10 7:12
professionalNagy Vilmos2-Jul-10 7:12 
GeneralRe: I want a Clever Text Display Pin
Luc Pattyn2-Jul-10 7:20
sitebuilderLuc Pattyn2-Jul-10 7:20 
GeneralRe: I want a Clever Text Display Pin
Nagy Vilmos2-Jul-10 10:53
professionalNagy Vilmos2-Jul-10 10:53 
GeneralRe: I want a Clever Text Display Pin
Luc Pattyn2-Jul-10 11:31
sitebuilderLuc Pattyn2-Jul-10 11:31 
GeneralRe: I want a Clever Text Display Pin
Nagy Vilmos2-Jul-10 21:44
professionalNagy Vilmos2-Jul-10 21:44 
GeneralRe: I want a Clever Text Display Pin
Mycroft Holmes2-Jul-10 22:31
professionalMycroft Holmes2-Jul-10 22:31 
QuestionCross Platform C#.NET Application Development [modified] Pin
LazyDragonfist2-Jul-10 5:02
LazyDragonfist2-Jul-10 5:02 

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.