micnie_2020

micnie_2020

  • NA
  • 137
  • 0

After SortMode Automatic, my function doesn't work

Nov 3 2011 10:05 PM
Hi All,

I trying to sort the datagrid grid column, after sorting i want it to trigger the function hide the row which the column data row equal to "-". Unfortunately. It's NOT working. But i put breakpoint. It's actually trigger the fuction & visble=false as well. Look Funny, it's doesn't hide my "-" row.

Please Advise.

Here is my code 2 method i used, both failed:

Method I

Datagrid Column
-----------------
this.dgvtbcRevByYearTotalRc.DataPropertyName = "value_total_rc";
this.dgvtbcRevByYearTotalRc.HeaderText = "Total...";
this.dgvtbcRevByYearTotalRc.Name = "dgvtbcRevsByYearTotalRc";
this.dgvtbcRevByYearTotalRc.ReadOnly = true;
this.dgvtbcRevByYearTotalRc.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
this.dgvtbcRevByYearTotalRc.Width = 60;
this.dgvtbcRevByYearTotalRc.DataGridView.Click += new System.EventHandler(this.lblTotalYTDDrillDownCaption_Click);


private void lblTotalYTDDrillDownCaption_Click(object sender, EventArgs e)
{

this.dgvtbcRevByYearTotalRc.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;

///Added by micheale to hide "-" row
foreach (DataGridViewRow item in dgvRevByYear.Rows)
{
   dgvRevByYear.CurrentCell = null; // To avoid Row associated with the currency manager's position cannot be made invisible

  if (item.Cells["dgvtbcRevenuesByYearTotalRc"].FormattedValue.ToString() == "-")
  {
     item.Visible = false;
  }

}
}


Method II

Datagrid Column
-----------------
this.dgvtbcRevByYearTotalRc.DataPropertyName = "value_total_rc";
this.dgvtbcRevByYearTotalRc.HeaderText = "Total...";
this.dgvtbcRevByYearTotalRc.Name = "dgvtbcRevsByYearTotalRc";
this.dgvtbcRevByYearTotalRc.ReadOnly = true;
this.dgvtbcRevByYearTotalRc.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
this.dgvtbcRevByYearTotalRc.Width = 60;
this.dgvtbcRevByYearTotalRc.DataGridView.Click += new System.EventHandler(this.lblTotalYTDDrillDownCaption_Click);


private void lblTotalYTDDrillDownCaption_Click(object sender, EventArgs e)
{

///Added by micheale to hide "-" row
foreach (DataGridViewRow item in dgvRevByYear.Rows)
{
dgvRevByYear.CurrentCell = null; // To avoid Row associated with the currency manager's position cannot be made invisible

if (item.Cells["dgvtbcRevenuesByYearTotalRc"].FormattedValue.ToString() == "-")
{
item.Visible = false;
}

}
}

Thank you.

Regards,
Micheale

Answers (4)