none
how can I show the date is empty, if the date is '01/01/1900' in a datagridview

    Question

  • I have a datagridview with the following structure. I have attached sample gridview with data

    this.grvListVehicle.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
                this.grvListVehicle.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
                this.Descr,
                this.TaxDate,
                this.DateInsured,
                this.yearRegister,
                this.Sorn,
                this.btnEdit});
                this.grvListVehicle.Location = new System.Drawing.Point(24, 36);
                this.grvListVehicle.Name = "grvListVehicle";
                this.grvListVehicle.RowTemplate.Height = 24;
                this.grvListVehicle.Size = new System.Drawing.Size(1318, 447);
                this.grvListVehicle.TabIndex = 0;
    
    And filling the data in to the gridview 
    mtVehicle obj = new mtVehicle();
                DataTable t = new DataTable();
                t = obj.spListVehicle();
                grvListVehicle.DataSource = t;

    How can I show the date as empty when the tax date is '01/01/1900'

    Please  help

     

    polachan


    • Edited by polachan Wednesday, January 03, 2018 10:28 PM
    Wednesday, January 03, 2018 10:22 PM

All replies

  • Hi polachan,

    Thank you for posting here.

    >>How can I show the date as empty when the tax date is '01/01/1900'

    For your question, what is the date? MotDate?

    If it is MotDate, you could try the following code. I make a simple example for your reference.

      private void button1_Click(object sender, EventArgs e)
            {
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (row.Cells["TaxDate"].Value.ToString() == "01/01/1990")
                    {
                        row.Cells["MotDate"].Value = string.Empty;
                    }
                }
            }
    
            private void _0104_Load(object sender, EventArgs e)
            {
                dataGridView1.AllowUserToAddRows = false;
                dataGridView1.ColumnCount = 2;
                dataGridView1.Columns[0].Name = "MotDate";
                dataGridView1.Columns[1].Name = "TaxDate";
    
                string[] row = new string[] { "1", "01/04/1990" };
                dataGridView1.Rows.Add(row);
                row = new string[] { "2", "01/01/1990" };
                dataGridView1.Rows.Add(row);
                row = new string[] { "3", "01/02/1990" };
                dataGridView1.Rows.Add(row);
                row = new string[] { "4", "01/03/1990" };
                dataGridView1.Rows.Add(row);
            }

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, January 04, 2018 8:31 AM
    Moderator
  • How can I show the date as empty when the tax date is '01/01/1900'

    Please  help

    You would load the grid manually from the datatable not using a Grid.Datasource to load the grid

    You would check the datatable column for the 1900 date. If the data is present, you simply don't put the data in the grid column or use Empty.String in the grid column.

    http://www.kettic.com/winforms_ui/csharp_guide/gridview_row_insert.shtml

    Thursday, January 04, 2018 10:00 AM