how to add 90 days to expiry date or subtract 90 days from system date
up vote
-1
down vote
favorite
now just add 90 days with expiry date or subtract 90 days from system date. it will solve my problem! i want that the row color is red when 90 days left to item expiry date
private void DgvStock_CellFormatting_1(object sender, DataGridViewCellFormattingEventArgs e)
foreach (DataGridViewRow row in DgvStock.Rows)
DateTime exp = Convert.ToDateTime(row.Cells["ExpDate"].Value);
if (exp <= System.DateTime.Now)
row.DefaultCellStyle.ForeColor = Color.White;
row.DefaultCellStyle.BackColor = Color.Red;
c#
add a comment |
up vote
-1
down vote
favorite
now just add 90 days with expiry date or subtract 90 days from system date. it will solve my problem! i want that the row color is red when 90 days left to item expiry date
private void DgvStock_CellFormatting_1(object sender, DataGridViewCellFormattingEventArgs e)
foreach (DataGridViewRow row in DgvStock.Rows)
DateTime exp = Convert.ToDateTime(row.Cells["ExpDate"].Value);
if (exp <= System.DateTime.Now)
row.DefaultCellStyle.ForeColor = Color.White;
row.DefaultCellStyle.BackColor = Color.Red;
c#
4
....and what's not working for you? have tried something? have you looked at the functionality thatDateTime
provides?
– Ofir Winegarten
Nov 11 at 11:18
Do not process all the rows in that event - your app will seem sluggish and slow with more than a few rows of data. The event arguments tell you which row needs to be formatted
– WelcomeOverflow
Nov 11 at 15:50
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
now just add 90 days with expiry date or subtract 90 days from system date. it will solve my problem! i want that the row color is red when 90 days left to item expiry date
private void DgvStock_CellFormatting_1(object sender, DataGridViewCellFormattingEventArgs e)
foreach (DataGridViewRow row in DgvStock.Rows)
DateTime exp = Convert.ToDateTime(row.Cells["ExpDate"].Value);
if (exp <= System.DateTime.Now)
row.DefaultCellStyle.ForeColor = Color.White;
row.DefaultCellStyle.BackColor = Color.Red;
c#
now just add 90 days with expiry date or subtract 90 days from system date. it will solve my problem! i want that the row color is red when 90 days left to item expiry date
private void DgvStock_CellFormatting_1(object sender, DataGridViewCellFormattingEventArgs e)
foreach (DataGridViewRow row in DgvStock.Rows)
DateTime exp = Convert.ToDateTime(row.Cells["ExpDate"].Value);
if (exp <= System.DateTime.Now)
row.DefaultCellStyle.ForeColor = Color.White;
row.DefaultCellStyle.BackColor = Color.Red;
c#
c#
edited Nov 11 at 11:18
Barr J
5,7871930
5,7871930
asked Nov 11 at 11:16
Saud Khan
52
52
4
....and what's not working for you? have tried something? have you looked at the functionality thatDateTime
provides?
– Ofir Winegarten
Nov 11 at 11:18
Do not process all the rows in that event - your app will seem sluggish and slow with more than a few rows of data. The event arguments tell you which row needs to be formatted
– WelcomeOverflow
Nov 11 at 15:50
add a comment |
4
....and what's not working for you? have tried something? have you looked at the functionality thatDateTime
provides?
– Ofir Winegarten
Nov 11 at 11:18
Do not process all the rows in that event - your app will seem sluggish and slow with more than a few rows of data. The event arguments tell you which row needs to be formatted
– WelcomeOverflow
Nov 11 at 15:50
4
4
....and what's not working for you? have tried something? have you looked at the functionality that
DateTime
provides?– Ofir Winegarten
Nov 11 at 11:18
....and what's not working for you? have tried something? have you looked at the functionality that
DateTime
provides?– Ofir Winegarten
Nov 11 at 11:18
Do not process all the rows in that event - your app will seem sluggish and slow with more than a few rows of data. The event arguments tell you which row needs to be formatted
– WelcomeOverflow
Nov 11 at 15:50
Do not process all the rows in that event - your app will seem sluggish and slow with more than a few rows of data. The event arguments tell you which row needs to be formatted
– WelcomeOverflow
Nov 11 at 15:50
add a comment |
3 Answers
3
active
oldest
votes
up vote
1
down vote
to add or substract days from current date you can do like this:
var date = DateTime.Now.AddDays(-90);
and change you code like:
if (exp <= System.DateTime.Now)
row.CellStyle.ForeColor = Color.White;
row.CellStyle.BackColor = Color.Red;
else
row.CellStyle.ForeColor = Color.Black;
row.CellStyle.BackColor = Color.White; // or some other origin color
looks like you using DefaultCellStyle
incorrectly. DefaultCellStyle
change style for all rows, but you need to change colors for specific row.
it does not working
– Saud Khan
Nov 11 at 12:41
@SaudKhan as you can see 3 similar answer was provided by 3 different developers with high reputation. I am sure that problem in your usage if this function. Just quick example (see attached image in my anser)
– Sergey Shulik
Nov 11 at 12:49
i did as you send but it change all row color...
– Saud Khan
Nov 11 at 12:54
looks like you usingDefaultCellStyle
incorrectly.DefaultCellStyle
change style for all rows, but you need to change colors for specific row. See my changes in answer. I don't remember exactly how to change styles in WinForms grid, so you need to find it by your self, but don't useDefaultCellStyle
– Sergey Shulik
Nov 11 at 13:04
add a comment |
up vote
0
down vote
How about
if (exp <= System.DateTime.Now.AddDays(-90))
{
//...
P.S: I would move the DateTime.Now outside the loop and save it into a variable once.
this is not working bro
– Saud Khan
Nov 11 at 12:40
add a comment |
up vote
0
down vote
try this:
foreach (DataGridViewRow row in DgvStock.Rows)
DateTime exp = DateTime.Parse(row.Cells["ExpDate"].Value + "");
if (exp <= System.DateTime.Today.AddDays(-90))
row.DefaultCellStyle.ForeColor = Color.White;
row.DefaultCellStyle.BackColor = Color.Red;
else
row.DefaultCellStyle.BackColor = Color.White;
it does not working
– Saud Khan
Nov 11 at 12:24
you have to try updated my answer
– Dhanushka Dayawansha
Nov 11 at 12:43
when i write this as all row colors change to red in datagrid view foreach (DataGridViewRow row in DgvStock.Rows) DateTime ExpDate = Convert.ToDateTime(row.Cells["ExpDate"].Value); if (ExpDate >= System.DateTime.Now.AddDays(-90)) row.DefaultCellStyle.ForeColor = Color.White; row.DefaultCellStyle.BackColor = Color.Red;
– Saud Khan
Nov 11 at 12:46
DateTime ExpDate = Convert.ToDateTime(row.Cells["ExpDate"].Value); if (ExpDate >= System.DateTime.Now.AddDays(-90))
– Saud Khan
Nov 11 at 12:47
if condition like that if (ExpDate <= System.DateTime.Now.AddDays(-90))
– Dhanushka Dayawansha
Nov 11 at 12:48
|
show 2 more comments
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
to add or substract days from current date you can do like this:
var date = DateTime.Now.AddDays(-90);
and change you code like:
if (exp <= System.DateTime.Now)
row.CellStyle.ForeColor = Color.White;
row.CellStyle.BackColor = Color.Red;
else
row.CellStyle.ForeColor = Color.Black;
row.CellStyle.BackColor = Color.White; // or some other origin color
looks like you using DefaultCellStyle
incorrectly. DefaultCellStyle
change style for all rows, but you need to change colors for specific row.
it does not working
– Saud Khan
Nov 11 at 12:41
@SaudKhan as you can see 3 similar answer was provided by 3 different developers with high reputation. I am sure that problem in your usage if this function. Just quick example (see attached image in my anser)
– Sergey Shulik
Nov 11 at 12:49
i did as you send but it change all row color...
– Saud Khan
Nov 11 at 12:54
looks like you usingDefaultCellStyle
incorrectly.DefaultCellStyle
change style for all rows, but you need to change colors for specific row. See my changes in answer. I don't remember exactly how to change styles in WinForms grid, so you need to find it by your self, but don't useDefaultCellStyle
– Sergey Shulik
Nov 11 at 13:04
add a comment |
up vote
1
down vote
to add or substract days from current date you can do like this:
var date = DateTime.Now.AddDays(-90);
and change you code like:
if (exp <= System.DateTime.Now)
row.CellStyle.ForeColor = Color.White;
row.CellStyle.BackColor = Color.Red;
else
row.CellStyle.ForeColor = Color.Black;
row.CellStyle.BackColor = Color.White; // or some other origin color
looks like you using DefaultCellStyle
incorrectly. DefaultCellStyle
change style for all rows, but you need to change colors for specific row.
it does not working
– Saud Khan
Nov 11 at 12:41
@SaudKhan as you can see 3 similar answer was provided by 3 different developers with high reputation. I am sure that problem in your usage if this function. Just quick example (see attached image in my anser)
– Sergey Shulik
Nov 11 at 12:49
i did as you send but it change all row color...
– Saud Khan
Nov 11 at 12:54
looks like you usingDefaultCellStyle
incorrectly.DefaultCellStyle
change style for all rows, but you need to change colors for specific row. See my changes in answer. I don't remember exactly how to change styles in WinForms grid, so you need to find it by your self, but don't useDefaultCellStyle
– Sergey Shulik
Nov 11 at 13:04
add a comment |
up vote
1
down vote
up vote
1
down vote
to add or substract days from current date you can do like this:
var date = DateTime.Now.AddDays(-90);
and change you code like:
if (exp <= System.DateTime.Now)
row.CellStyle.ForeColor = Color.White;
row.CellStyle.BackColor = Color.Red;
else
row.CellStyle.ForeColor = Color.Black;
row.CellStyle.BackColor = Color.White; // or some other origin color
looks like you using DefaultCellStyle
incorrectly. DefaultCellStyle
change style for all rows, but you need to change colors for specific row.
to add or substract days from current date you can do like this:
var date = DateTime.Now.AddDays(-90);
and change you code like:
if (exp <= System.DateTime.Now)
row.CellStyle.ForeColor = Color.White;
row.CellStyle.BackColor = Color.Red;
else
row.CellStyle.ForeColor = Color.Black;
row.CellStyle.BackColor = Color.White; // or some other origin color
looks like you using DefaultCellStyle
incorrectly. DefaultCellStyle
change style for all rows, but you need to change colors for specific row.
edited Nov 11 at 13:02
answered Nov 11 at 11:19
Sergey Shulik
678824
678824
it does not working
– Saud Khan
Nov 11 at 12:41
@SaudKhan as you can see 3 similar answer was provided by 3 different developers with high reputation. I am sure that problem in your usage if this function. Just quick example (see attached image in my anser)
– Sergey Shulik
Nov 11 at 12:49
i did as you send but it change all row color...
– Saud Khan
Nov 11 at 12:54
looks like you usingDefaultCellStyle
incorrectly.DefaultCellStyle
change style for all rows, but you need to change colors for specific row. See my changes in answer. I don't remember exactly how to change styles in WinForms grid, so you need to find it by your self, but don't useDefaultCellStyle
– Sergey Shulik
Nov 11 at 13:04
add a comment |
it does not working
– Saud Khan
Nov 11 at 12:41
@SaudKhan as you can see 3 similar answer was provided by 3 different developers with high reputation. I am sure that problem in your usage if this function. Just quick example (see attached image in my anser)
– Sergey Shulik
Nov 11 at 12:49
i did as you send but it change all row color...
– Saud Khan
Nov 11 at 12:54
looks like you usingDefaultCellStyle
incorrectly.DefaultCellStyle
change style for all rows, but you need to change colors for specific row. See my changes in answer. I don't remember exactly how to change styles in WinForms grid, so you need to find it by your self, but don't useDefaultCellStyle
– Sergey Shulik
Nov 11 at 13:04
it does not working
– Saud Khan
Nov 11 at 12:41
it does not working
– Saud Khan
Nov 11 at 12:41
@SaudKhan as you can see 3 similar answer was provided by 3 different developers with high reputation. I am sure that problem in your usage if this function. Just quick example (see attached image in my anser)
– Sergey Shulik
Nov 11 at 12:49
@SaudKhan as you can see 3 similar answer was provided by 3 different developers with high reputation. I am sure that problem in your usage if this function. Just quick example (see attached image in my anser)
– Sergey Shulik
Nov 11 at 12:49
i did as you send but it change all row color...
– Saud Khan
Nov 11 at 12:54
i did as you send but it change all row color...
– Saud Khan
Nov 11 at 12:54
looks like you using
DefaultCellStyle
incorrectly. DefaultCellStyle
change style for all rows, but you need to change colors for specific row. See my changes in answer. I don't remember exactly how to change styles in WinForms grid, so you need to find it by your self, but don't use DefaultCellStyle
– Sergey Shulik
Nov 11 at 13:04
looks like you using
DefaultCellStyle
incorrectly. DefaultCellStyle
change style for all rows, but you need to change colors for specific row. See my changes in answer. I don't remember exactly how to change styles in WinForms grid, so you need to find it by your self, but don't use DefaultCellStyle
– Sergey Shulik
Nov 11 at 13:04
add a comment |
up vote
0
down vote
How about
if (exp <= System.DateTime.Now.AddDays(-90))
{
//...
P.S: I would move the DateTime.Now outside the loop and save it into a variable once.
this is not working bro
– Saud Khan
Nov 11 at 12:40
add a comment |
up vote
0
down vote
How about
if (exp <= System.DateTime.Now.AddDays(-90))
{
//...
P.S: I would move the DateTime.Now outside the loop and save it into a variable once.
this is not working bro
– Saud Khan
Nov 11 at 12:40
add a comment |
up vote
0
down vote
up vote
0
down vote
How about
if (exp <= System.DateTime.Now.AddDays(-90))
{
//...
P.S: I would move the DateTime.Now outside the loop and save it into a variable once.
How about
if (exp <= System.DateTime.Now.AddDays(-90))
{
//...
P.S: I would move the DateTime.Now outside the loop and save it into a variable once.
answered Nov 11 at 11:26
Jannik
1,04821744
1,04821744
this is not working bro
– Saud Khan
Nov 11 at 12:40
add a comment |
this is not working bro
– Saud Khan
Nov 11 at 12:40
this is not working bro
– Saud Khan
Nov 11 at 12:40
this is not working bro
– Saud Khan
Nov 11 at 12:40
add a comment |
up vote
0
down vote
try this:
foreach (DataGridViewRow row in DgvStock.Rows)
DateTime exp = DateTime.Parse(row.Cells["ExpDate"].Value + "");
if (exp <= System.DateTime.Today.AddDays(-90))
row.DefaultCellStyle.ForeColor = Color.White;
row.DefaultCellStyle.BackColor = Color.Red;
else
row.DefaultCellStyle.BackColor = Color.White;
it does not working
– Saud Khan
Nov 11 at 12:24
you have to try updated my answer
– Dhanushka Dayawansha
Nov 11 at 12:43
when i write this as all row colors change to red in datagrid view foreach (DataGridViewRow row in DgvStock.Rows) DateTime ExpDate = Convert.ToDateTime(row.Cells["ExpDate"].Value); if (ExpDate >= System.DateTime.Now.AddDays(-90)) row.DefaultCellStyle.ForeColor = Color.White; row.DefaultCellStyle.BackColor = Color.Red;
– Saud Khan
Nov 11 at 12:46
DateTime ExpDate = Convert.ToDateTime(row.Cells["ExpDate"].Value); if (ExpDate >= System.DateTime.Now.AddDays(-90))
– Saud Khan
Nov 11 at 12:47
if condition like that if (ExpDate <= System.DateTime.Now.AddDays(-90))
– Dhanushka Dayawansha
Nov 11 at 12:48
|
show 2 more comments
up vote
0
down vote
try this:
foreach (DataGridViewRow row in DgvStock.Rows)
DateTime exp = DateTime.Parse(row.Cells["ExpDate"].Value + "");
if (exp <= System.DateTime.Today.AddDays(-90))
row.DefaultCellStyle.ForeColor = Color.White;
row.DefaultCellStyle.BackColor = Color.Red;
else
row.DefaultCellStyle.BackColor = Color.White;
it does not working
– Saud Khan
Nov 11 at 12:24
you have to try updated my answer
– Dhanushka Dayawansha
Nov 11 at 12:43
when i write this as all row colors change to red in datagrid view foreach (DataGridViewRow row in DgvStock.Rows) DateTime ExpDate = Convert.ToDateTime(row.Cells["ExpDate"].Value); if (ExpDate >= System.DateTime.Now.AddDays(-90)) row.DefaultCellStyle.ForeColor = Color.White; row.DefaultCellStyle.BackColor = Color.Red;
– Saud Khan
Nov 11 at 12:46
DateTime ExpDate = Convert.ToDateTime(row.Cells["ExpDate"].Value); if (ExpDate >= System.DateTime.Now.AddDays(-90))
– Saud Khan
Nov 11 at 12:47
if condition like that if (ExpDate <= System.DateTime.Now.AddDays(-90))
– Dhanushka Dayawansha
Nov 11 at 12:48
|
show 2 more comments
up vote
0
down vote
up vote
0
down vote
try this:
foreach (DataGridViewRow row in DgvStock.Rows)
DateTime exp = DateTime.Parse(row.Cells["ExpDate"].Value + "");
if (exp <= System.DateTime.Today.AddDays(-90))
row.DefaultCellStyle.ForeColor = Color.White;
row.DefaultCellStyle.BackColor = Color.Red;
else
row.DefaultCellStyle.BackColor = Color.White;
try this:
foreach (DataGridViewRow row in DgvStock.Rows)
DateTime exp = DateTime.Parse(row.Cells["ExpDate"].Value + "");
if (exp <= System.DateTime.Today.AddDays(-90))
row.DefaultCellStyle.ForeColor = Color.White;
row.DefaultCellStyle.BackColor = Color.Red;
else
row.DefaultCellStyle.BackColor = Color.White;
edited Nov 11 at 13:01
answered Nov 11 at 11:43
Dhanushka Dayawansha
31119
31119
it does not working
– Saud Khan
Nov 11 at 12:24
you have to try updated my answer
– Dhanushka Dayawansha
Nov 11 at 12:43
when i write this as all row colors change to red in datagrid view foreach (DataGridViewRow row in DgvStock.Rows) DateTime ExpDate = Convert.ToDateTime(row.Cells["ExpDate"].Value); if (ExpDate >= System.DateTime.Now.AddDays(-90)) row.DefaultCellStyle.ForeColor = Color.White; row.DefaultCellStyle.BackColor = Color.Red;
– Saud Khan
Nov 11 at 12:46
DateTime ExpDate = Convert.ToDateTime(row.Cells["ExpDate"].Value); if (ExpDate >= System.DateTime.Now.AddDays(-90))
– Saud Khan
Nov 11 at 12:47
if condition like that if (ExpDate <= System.DateTime.Now.AddDays(-90))
– Dhanushka Dayawansha
Nov 11 at 12:48
|
show 2 more comments
it does not working
– Saud Khan
Nov 11 at 12:24
you have to try updated my answer
– Dhanushka Dayawansha
Nov 11 at 12:43
when i write this as all row colors change to red in datagrid view foreach (DataGridViewRow row in DgvStock.Rows) DateTime ExpDate = Convert.ToDateTime(row.Cells["ExpDate"].Value); if (ExpDate >= System.DateTime.Now.AddDays(-90)) row.DefaultCellStyle.ForeColor = Color.White; row.DefaultCellStyle.BackColor = Color.Red;
– Saud Khan
Nov 11 at 12:46
DateTime ExpDate = Convert.ToDateTime(row.Cells["ExpDate"].Value); if (ExpDate >= System.DateTime.Now.AddDays(-90))
– Saud Khan
Nov 11 at 12:47
if condition like that if (ExpDate <= System.DateTime.Now.AddDays(-90))
– Dhanushka Dayawansha
Nov 11 at 12:48
it does not working
– Saud Khan
Nov 11 at 12:24
it does not working
– Saud Khan
Nov 11 at 12:24
you have to try updated my answer
– Dhanushka Dayawansha
Nov 11 at 12:43
you have to try updated my answer
– Dhanushka Dayawansha
Nov 11 at 12:43
when i write this as all row colors change to red in datagrid view foreach (DataGridViewRow row in DgvStock.Rows) DateTime ExpDate = Convert.ToDateTime(row.Cells["ExpDate"].Value); if (ExpDate >= System.DateTime.Now.AddDays(-90)) row.DefaultCellStyle.ForeColor = Color.White; row.DefaultCellStyle.BackColor = Color.Red;
– Saud Khan
Nov 11 at 12:46
when i write this as all row colors change to red in datagrid view foreach (DataGridViewRow row in DgvStock.Rows) DateTime ExpDate = Convert.ToDateTime(row.Cells["ExpDate"].Value); if (ExpDate >= System.DateTime.Now.AddDays(-90)) row.DefaultCellStyle.ForeColor = Color.White; row.DefaultCellStyle.BackColor = Color.Red;
– Saud Khan
Nov 11 at 12:46
DateTime ExpDate = Convert.ToDateTime(row.Cells["ExpDate"].Value); if (ExpDate >= System.DateTime.Now.AddDays(-90))
– Saud Khan
Nov 11 at 12:47
DateTime ExpDate = Convert.ToDateTime(row.Cells["ExpDate"].Value); if (ExpDate >= System.DateTime.Now.AddDays(-90))
– Saud Khan
Nov 11 at 12:47
if condition like that if (ExpDate <= System.DateTime.Now.AddDays(-90))
– Dhanushka Dayawansha
Nov 11 at 12:48
if condition like that if (ExpDate <= System.DateTime.Now.AddDays(-90))
– Dhanushka Dayawansha
Nov 11 at 12:48
|
show 2 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248172%2fhow-to-add-90-days-to-expiry-date-or-subtract-90-days-from-system-date%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
....and what's not working for you? have tried something? have you looked at the functionality that
DateTime
provides?– Ofir Winegarten
Nov 11 at 11:18
Do not process all the rows in that event - your app will seem sluggish and slow with more than a few rows of data. The event arguments tell you which row needs to be formatted
– WelcomeOverflow
Nov 11 at 15:50