2016-07-15 6 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; 

そして、ここでは、ソートが正しく動作しているが、問題は、e.Valueが非表示であるべきである

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

私dgv_details_CellFormattingイベントハンドラです私のフォームのロード中に私のデータソースを置きます。 結果は、私は本当に助けを必要と

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

今すぐ清潔なソリューションと再構築してみてください –

関連する問題