2016-07-15 35 views
1

美好的一天,我将表格中的查询显示在数据网格中。但是我的代码有问题。我试图在我的dgview_CellFormatting中调试并添加断点,但是我的代码没有进入单元格格式的事件处理程序。我不知道为什么。C#WinForm DataGrid CellFormatting在数据源问题中不起作用

这是我的代码。我把我的数据源,在我的窗体加载

// dgv_details is supposed to be my datagrid view name. 

DataTable table; 

table = balreport.SelectDetails(belreport); // responsible for fetching data from the database. 

this.dgv_details.DataSource = table; 

this.dgv_details.Sort(this.dgv_details.Columns[0], ListSortDirection.Ascending); 
// For sorting the data 
foreach (DataGridViewColumn column in this.dgv_details.Columns) 
{ 
    column.SortMode = DataGridViewColumnSortMode.NotSortable; 
} 

this.dgv_details.CellFormatting += dgv_details_CellFormatting; 

这是我的dgv_details_CellFormatting事件处理

if (e.ColumnIndex == 0 && e.RowIndex > 0) 
{ 
    if (dgv_salesdetails[0, e.RowIndex].Value == dgv_salesdetails[0, e.RowIndex - 1].Value) 
    e.Value = ""; 
} 

的排序工作正常,但问题是,在e.Value应该是隐藏。 结果应该是这样的图像

enter image description here

我真的需要帮助。

+0

也'e.FormattingApplied = true;'在事件处理程序 – ASh

+0

不,它给了我很多错误在我的对话框中。 :/ –

+0

你的网络正在填充或不是 –

回答

1

使用本

// dgv_details is supposed to be my datagrid view name. 
this.dgv_details.CellFormatting += dgv_details_CellFormatting; 
DataTable table; 

table = balreport.SelectDetails(belreport); // responsible for fetching data from the database. 

this.dgv_details.DataSource = table; 

this.dgv_details.Sort(this.dgv_details.Columns[0], ListSortDirection.Ascending); 
// For sorting the data 
foreach (DataGridViewColumn column in this.dgv_details.Columns) 
{ 
    column.SortMode = DataGridViewColumnSortMode.NotSortable; 
} 

事业的DataGrid CellFormatting事件不工作时,数据网格填充。

+0

也不管用。 –

+0

请帮我如何解决这个 –

+0

我只是检查它的工作。现在干净的解决方案和重建,并尝试 –