winforms - Datagridview custom row highlight -


I have DataGridView (WinForms, C #). What I wanted to do is to divide the grid on the left / right side, so when I click on the left part (3,3), for example, when click on the right part (6, 6) Will be highlighted.

  Col1 | Col2 | Col3 | Call 4 ------------------------- 1 1 2 2 3 3 4 4 5 5 6 6  

Receiving value is not a problem, but highlights ..?

int iCol = dgv.CurrentCell.ColumnIndex; If (iCol == 0 || iCol == 1) // on left side {} else // right side {}

I hope this helps you, but you should not write the column index directly into the code, I think controlling the index with mathematical expression is a better solution. Apart from this, this code will be slower than large data, so that you can select the column. But if you select the column, then clicking on the column header will prevent the rows from sorting.

  The private sub-DataGridView1_CellClick (Sender as System.Object, and System.Down.Forms.DataGridViewCellEventArgs) handles DataGridView1 .CellClick DataGridView1.SelectionMode = Select DataGridViewSelectionMode.Cell if e ColumnIndex & lt; DataGridView1.ColumnCount / 2 then DataGridView1.Columns in DataGridViewColumn for each c if c.index & lt; DataGridView1.ColumnCount / 2 after each DataGridViewRow in DataGridView1.Rows r.Cells (c.Index). Style.BackColor = Color.Blue in DataGridView1.Rows r.Cells (c.Index) as the DataGridViewRow for next each. .Style.BackColor = Color.Gray Next End If for each C, in the DataGrade view column, next to the DataGride view column, if c. Index & gt; = DataGridView1.ColumnCount / 2 then DataGridView1.Rows in the DataGridView1.Rows r.Cells (c. Index). Style.BackColor = Color.Blue DataGridView1.Rows as DataGridViewRow for each of the next RSS r.Cells (c .index) .Style.BackColor = Color.Gray Next End if Next End End Sub  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -