Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > How to set Row header in DataGridView for ColumnIndex = -1 & RowIndex = -1, without any drawing?
 

How to set Row header in DataGridView for ColumnIndex = -1 & RowIndex = -1, without any drawing?

How to set Row header in DataGridView for ColumnIndex = -1 & RowIndex = -1, without any drawing?

I have already done using drawing at CellPainting event, but when I re-size first column other column headers (ColumnIndex>=0) are shown with headers of ColumnIndex = -1

---------------------------------
col-1|col0|col1|--------
---------------------------------

after re-sizing col-1 it is displaying like this:

-----------------------------------------------------------------
col-1|col0|col1|--------|col0|col1|col2|col3|----------------
-----------------------------------------------------------------
<-----re-sizing-------->

Here only col-1 has to be displayed before 1st --------
-----------------------------------------------------------------
|col0|col1|col2|col3|----------------
-----------------------------------------------------------------
<<re-sizing

If I re-size it to 0 length to the left as to hide RowHeader then after re-sizing again it displays only blank like this

-----------------------------------------------------------------
|col0|col1|col2|col3|----------------
-----------------------------------------------------------------
<-----re-sizing-------->


How to resolve it or is there any alternative?
Gaurav Mohan  Sunday, July 19, 2009 2:02 AM
Hi Mohan,

Based on my understanding, you'd like to draw text on the column header with the row index of -1 and the column index of -1. If I'm off base, please feel free to let me know.

To get what you want, handle the CellPainting event of the DataGridView and draw text on the column header in question. When the user resizes the columns, the CellPainting event will be raised and the column header will be repainted in time. The following isa sample:

dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)

if (e.ColumnIndex == -1 && e.RowIndex == -1)

false);

"col-1", e.CellStyle.Font, new SolidBrush(e.CellStyle.ForeColor), e.CellBounds);

true;


Please remember to mark the replies as answers if they help and unmark them if they provide no help. end us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.
Linda Liu  Wednesday, July 29, 2009 2:35 AM

You can use google to search for other answers

Custom Search

More Threads

• Master / Detail datagridview with relation from type string
• Windows Application and Access Database
• Add Event CheckedChanged to DataGridView
• How can i make a DataGridViewCell to blink ?
• ListBox DataBinding Issue
• Operation did not succeed because the program cannot commit or quit a cell value change.
• How to load XML objects into custom .Net classes?
• How to disable DataGridViewButtonColumn in a particular rows
• How to set value? control.DataBindings["Text"].BindingManagerBase.Current = ?
• Binding a textbox to the main Data Connection