2016-07-15 15 views
1

Guten Tag, ich zeige meine Abfragen von Tabelle in das Datagrid. Aber ich habe ein Problem mit meinen Codes. Ich habe versucht, in meinem dgview_CellFormatting zu debuggen und einen Unterbrechungspunkt hinzuzufügen, aber der my-Code geht nicht zum Ereignishandler der Zellenformatierung. Ich weiß nicht warum.C# WinForm DataGrid CellFormatting funktioniert nicht in Datenquellenprobleme

Hier ist mein Code. Ich legte meine Datenquelle in meiner Form Last

// 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; 

Und hier ist mein dgv_details_CellFormatting Event-Handler

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

Die Sortierung richtig funktioniert, aber das Problem ist, sollte die e.Value verbergen sein. Das Ergebnis sollte so etwas wie dieses Bild sein

enter image description here

ich wirklich Hilfe benötigen.

+0

tun Sie auch 'e.FormattingApplied = true;' in Event-Handler – ASh

+0

Nein, es gibt mir eine Menge Fehler in meinem Dialogfeld. :/ –

+0

Ihr Gürtel füllt oder nicht –

Antwort

1

Verwendung dieses

// 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; 
} 

Ursache Datagrid-Ereignis Cellformatting funktioniert, wenn Datagrid füllen.

+0

Funktioniert auch nicht. –

+0

Bitte helfen Sie, wie kann ich das beheben –

+0

ich überprüfe es einfach seine Arbeit. Jetzt saubere Lösung und neu erstellen und versuchen, –