TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Zeb Muhammad
NA
67
18.2k
Changing Color of Datagridview Rows with effect of Days Qty.
Sep 18 2017 11:15 PM
I facing problem to change color of DGV Row w.e.o Quantity of Remaining days. I tried it but i got error. PLease, check my code.
public
void
RowsColor()
{
for
(
int
i = 0; i < dataGridView1.Rows.Count; i++)
{
int
val = Int32.Parse(dataGridView1.Rows[i].Cells[5].Value.ToString());
if
(val < 14)
{
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Red;
}
else
{
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Green;
}
}
}
and I called this
private
void
btn_Show_Click(
object
sender, EventArgs e)
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText =
"SELECT pro_ID,pur_Date,pur_Batch as BatchNo, pur_ItemName as ItemName,pur_ExpDate as ExpiryDate, DATEDIFF(DAY, GETDATE(), pur_ExpDate) AS RemainingDays FROM pur_tab WHERE pur_Date BETWEEN '"
+dt_From.Value.ToString(
"yyyy-MM-dd"
)+
"' AND '"
+ dt_To.Value.ToString(
"yyyy-MM-dd"
) +
"'"
;
cmd.ExecuteNonQuery();
dt =
new
DataTable();
da =
new
SqlDataAdapter(cmd);
da.Fill(dt);
dataGridView1.DataSource = dt;
RowsColor();
con.Close();
}
I got error An "unhandled exception of type 'System.NullReferenceException' occurred in MMS1.exe
“Object reference not set to an instance of an object.”}”
Please , help me.
Reply
Answers (
1
)
is it possible to use one View for multiple controller
Login form using local database