Click here to Skip to main content
15,745,232 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I don't want to show any row in highlighted mode.
by default it should be in highlight mode for the top row of Datagridview.

i tried Datagridview1.ClearSelection();
but still the top row is displayed in highlighted mode.

here is my code

<pre><pre lang="C++">private void FillGridView()
DataTable dtfillgrid = new DataTable();
dtfillgrid = dc.GetDataTable(&quot;Select * From SIF Where UID=&quot; + Convert.ToInt32(Constants.NodetooltipUnit));
DataTable dtClassificationSIFIDs = new DataTable();
dtClassificationSIFIDs = dc.GetDataTable(&quot;Select SIFID from ClassificationSIF&quot;);
if (dtfillgrid.Rows.Count &gt; 0)
dgrid.DataSource = dtfillgrid;
dgrid.Columns[&quot;SIFID&quot;].Visible = false;
dgrid.Columns[&quot;UID&quot;].Visible = false;
//dgrid.Rows[0].Selected = false;
if (dtClassificationSIFIDs.Rows.Count &gt; 0)
for (int i = 0; i &lt; dtClassificationSIFIDs.Rows.Count; i++)
for (int j = 0; j &lt; dgrid.Rows.Count; j++)
if (dtClassificationSIFIDs.Rows[i][&quot;SIFID&quot;].ToString().Equals(dgrid.Rows[j].Cells[&quot;SIFID&quot;].Value.ToString()))
dgrid.Rows[j].DefaultCellStyle.BackColor = Color.Green;
catch (Exception ex)

let me know if u have any idea.

Updated 18-May-23 7:21am
koool.kabeer 29-Jul-10 8:31am    
well you mean to say that by default the first cell of top row of DataGridView
is highlighted everytime... which you don't want yeah that "ClearSelection()" must work.....
koool.kabeer 29-Jul-10 8:33am    
if you provide quite clear means ..... where you are setting the Data of DataGridView and where you are calling the "ClearSelection()" method.... that may be quite easy to answer for expertise

I guess you must give time for the grid to be loaded so you must put the ClearSelection in the databindingcomplete because if you call ClearSelection after filling the grid, the clearselection will execute before the grid draws itself (thus selecting 1st row right after being painted)

private void dgvSchedule_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
Share this answer
dataGridView1.Rows[0].Selected = false;
Share this answer
Pawan Kiran 30-Jul-10 0:00am    
i tried this one,but not solved the issue.
ninty 16-Aug-14 4:25am    
not working
try it
this line of code solve your problem
Share this answer
Pawan Kiran 29-Jul-10 23:59pm    
SelectedIndex is not there for Datagridview control.
dgrid.DataGridView.CurrentCell = Nothing
Share this answer
But caution as other events can occur after Load... such as _RowPrePaint so a currentcell = nothing in those events may resolve your issue as well.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900