Friday, 15 June 2012

c# - DataGridView CellFormatting event preventing form painting -


I am using C #, Winforms and Net 3.5

In my form a custom < Code> Datagrid view (Double buffer has been given to prevent spry during my cellforming events). When I search a database, I bind the resulting dataset to datagridview

I take the cell formatting event to color the row to a certain color on my data.

My DataGridview Code:

  resultsGridView.DataSource = results.DefaultViewManager.DataSet.Tables [0]; ResultsGridView.AlternatingRowsDefaultCellStyle.BackColor = Color.AliceBlue; ResultsGridView.BorderStyle = Border Style. Fix 3D; ResultsGridView.CellFormatting + = New DataGridViewCellFormattingEventHandler (resultsGridView_CellFormatting);  

My cell formatting code:

  zero results Gridview_Gel formatting (object sender, data grid visual formatting request e) {int rowIndex = e.RowIndex; Data GridviewerROOO = Results Gridview Ros [lineindex]; If ((bool) therow.Cells ["sealed"]. Value == true) {therow.DefaultCellStyle.BackColor = Color.Pink; } If (therow.Cells ["database"]. String == "PNG" as value) {torow.DefaultCellStyle.BackColor = Color.LightGreen; }}  

Everything works great besides this, when I handle cell formatting, the paint event of the whole form stops. Blinking is turned off in the cursor text box, and the manstrip of the form looks like this:

The top one is before the research, after the menu down until I click the mouse on the menu Yes, I will not redo it again, and then will be in the way to highlight the last item when I take the mouse out of the menubar. Due to the transfer of the form, it needs to be repainted, but then the problem remains.

The database resolves the problem completely in the resultsGridView.CellFormatting line in the gridview code.

Am I misrepresenting cells or do I need to handle some more?

You are probably creating an exception inside this event. I'm not sure how the handling is defined, but with the catch of try, the code will be a first step around.

  try {int rowIndex = e.RowIndex; ....} (pre-exception) {System.Diagnostics.Trace.Error (ex.message); }  

On the other hand, I do not think that therow.Cells ["sealed"] will work therow.Cells ["dataGridViewTextBoxColumn2"] The cell is indexed by the column name , not DataPropertyName .


No comments:

Post a Comment