0 votes
in Education by (1.7m points)
I have a problem. DataGridView displays only date if time is midnight. First I thought that is because of my LINQ query which is dataGridView's data source. I couldn't change the query so I decided to add zeros from code. This is my code:

            for (int i = 0; i < dataGridViewRaporty.Rows.GetRowCount(DataGridViewElementStates.Visible); i++)

            {

                for (int j = 0; j < dataGridViewRaporty.Columns.GetColumnCount(DataGridViewElementStates.Visible); j++)

                {

                    string wartoscKomorki = dataGridViewRaporty.Rows[i].Cells[j].Value.ToString();

                    if (wartoscKomorki.Contains("-") && wartoscKomorki.Length == 10){

                        wartoscKomorki = wartoscKomorki + " 00:00";

                        dataGridViewRaporty.Rows[i].Cells[j].Value = wartoscKomorki.ToString();

                    }

                }

            }

I was surprised because zeros weren't added. Then I displayed those values in MessageBoxes and zeros appeared there. The conclusion is that dataGridView has got those values with zeros but doesn't show them. Is there any solution to show full DateTime format?

JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by (1.7m points)
As I said all was because of dataGridView behaviour. This is the solution:

dataGridViewRaporty.Columns[3].DefaultCellStyle.Format= "yyyy-MM-dd HH:mm";
...