hide row if column 4 or every row is (date < datenow)

roipatrick

New member
Joined
Mar 19, 2014
Messages
1
Programming Experience
5-10
I only wanted to hide a row if startdate column of that row has this statement (startdate < presentdate). It deleted but only 1 row and I want to delete all rows if they have the statement (dtartdate < presentdate) is satisfied. But i always come accross errors. Please help me guys....I need this one desparately. Thank you in advance and i apologize for my english.

C#:
void LoadSource()        {
            //string dateInString = Convert.ToString(Convert.ToDateTime(_dr[4]));
            //string dateInString = Convert.ToString(Convert.ToDateTime(RaDate));
            
            //DateTime startdate = DateTime.Parse(dateInString);
            //DateTime datelimit = startdate.AddDays(90);
            //int counter = 0;
            _fd = new FinancialData();
            if (cboType.SelectedIndex == 0) //&& DateTime.Now > datelimit)
                        grdDetails.DataSource = _fd.RetrievePayments();
            DataTable _dtPayment = _fd.RetrievePayments();
            if (grdDetails.DataSource == null)
            {
                MessageBox.Show("sample");
            }
            else
            {
                MessageBox.Show("smple");
            }
            string item = grdDetails[grdDetails.CurrentCell.ColumnIndex,
grdDetails.CurrentCell.RowIndex].Value.ToString();
            if (item != null)
            {
                int di = 0;
                int id = Convert.ToInt32(grdDetails[di, grdDetails.CurrentCell.RowIndex].Value);
                foreach (DataRow _dr in _dtPayment.Rows)
                {
                    var now = DateTime.Now;
                    if (DateTime.Parse(_dr[4].ToString()) < now)
                    {
                        this.grdDetails.Rows[id].Visible = false;
                    }
                    id++;
                    di++;
                }
            }
            
            MessageBox.Show(grdDetails.DataSource);
            else if (cboType.SelectedIndex == 1)// && DateTime.Now > datelimit)
                grdDetails.DataSource = _fd.RetrieveRemittanceAdvices();
            else
                grdDetails.DataSource = null;
        
        }

or if you can rephrase my whole code then thank you....Please help me guys...
 
Firstly, rows of what? It looks like a DataGridView from the code but we shouldn't have to work it out from the code; you should be providing a FULL and CLEAR description.

While we're on the subject of clear descriptions, your title says "hide" but in your post you say "delete". They are two very different things. Again, it looks like you want to hide the rows from the code but we shouldn't have to work out what you want to do from code that you yourself say doesn't actually do what you want.

It looks from the code that what you actually want is to hide rows in a DataGridView whose data comes from a DataTable. In that case, you should either use a WHERE clause in your query to exclude the records that you don't want to see in the first place or, if that's not appropriate, use the Filter property of a BindingSource. Either way, populate your DataTable, bind it to a BindingSource and then bind that to the grid. You can then set the Filter property of that BindingSource and only rows that match the specified criteria will be displayed.
 

Latest posts

Back
Top Bottom