Note that there are some explanatory texts on larger screens.

plurals
  1. PORemove blue colored row from DataGridView WinForms
    primarykey
    data
    text
    <p>When I fill a DataGridView row by row (calling it's add function), the top row gets blue colored. It's not selected because I tried ClearSelection() also but it didnt work. It's giving the wrong illusion that the first row is selected.</p> <p>How to get rid of it?</p> <pre><code> void FillDGV() { dataGridViewParties.Rows.Clear(); for (int i = 0; i &lt; dataGridViewParties.Columns.Count; i++) { dataGridViewParties.Columns[i].Width = this.Width / dataGridViewParties.Columns.Count; } DataTable partyTbl = UtilityClass.GetDataTable(@"SELECT [PartyID] ,[PartyName] ,[PartyAddress] ,[PartyState] ,[PartyCity] ,[PartyPhone] FROM [VegiManager].[dbo].[Parties] WHERE [PartyName] LIKE '" + textBoxPartySearch.Text + "%' "); foreach (DataRow dr in partyTbl.Rows) { dataGridViewParties.Rows.Add(1); dataGridViewParties.Rows[dataGridViewParties.Rows.Count - 1].Cells[0].Value = dr["PartyID"].ToString(); dataGridViewParties.Rows[dataGridViewParties.Rows.Count - 1].Cells[1].Value = dr["PartyName"].ToString(); dataGridViewParties.Rows[dataGridViewParties.Rows.Count - 1].Cells[2].Value = dr["PartyAddress"].ToString(); dataGridViewParties.Rows[dataGridViewParties.Rows.Count - 1].Cells[3].Value = dr["PartyState"].ToString(); dataGridViewParties.Rows[dataGridViewParties.Rows.Count - 1].Cells[4].Value = dr["PartyCity"].ToString(); dataGridViewParties.Rows[dataGridViewParties.Rows.Count - 1].Cells[5].Value = dr["PartyPhone"].ToString(); } if (dataGridViewParties.Rows.Count &gt; 0) { dataGridViewParties.ClearSelection(); dataGridViewParties.CurrentCell = null; } } </code></pre> <p>In the debugger I found that CurrentCell is already null before DataGridViewParties.CurrentCell = null; executes.</p> <p>This question <a href="http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/c440c4f6-6dfc-47b6-97c0-1ce49c105b64/" rel="nofollow">http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/c440c4f6-6dfc-47b6-97c0-1ce49c105b64/</a> is also related to it but does not offer a solution.</p> <p>EDIT: Its weird but it works for Load event, I was doing it in constructor. I want that when the first row is selected and when the user presses the UP arrow key, the focus moves to a certain textbox. But in this case it does not work (first row appears blue)</p> <pre><code> private void dataGridViewInwards_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Up &amp;&amp; dataGridViewParties.SelectedRows.Count &gt; 0 &amp;&amp; dataGridViewParties.SelectedRows[0].Index == 0) { textBoxPartySearch.Focus(); dataGridViewParties.ClearSelection(); dataGridViewParties.CurrentCell = null; } else if (e.KeyCode == Keys.Up &amp;&amp; dataGridViewParties.SelectedRows.Count == 0) { textBoxPartySearch.Focus(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload