Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

C# DataGridView: First row is being selected by default

$
0
0
Hai All, 

I have a WinForm which is having several tabs placed on it and one of the tab is having a DataGridView control which is ReadOnly always. The main problems is, datagridview control will select first row by default every time. I would expect nothing to be selected. 

I have tried clearing selection after data-binding. But, same behavior. Please suggest me to address my problem. 

Below is the code while dataBinding (in the Property Set block):***************

m_items = value;
dataGridView1.AutoGenerateColumns = false;
bindingSource.DataSource = null;
bindingSource.DataSource = m_items;
dataGridView1.DataSource = bindingSource;
dataGridView1.Refresh(); 

Below are my DataGridView Settings:******************

this.dataGridView1.MultiSelect = false;
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.ReadOnly = true;
this.dataGridView1.RowHeadersWidth = 20;
this.dataGridView1.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing;
this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dataGridView1.Size = new System.Drawing.Size(263, 130);
this.dataGridView1.TabIndex = 0;
this.dataGridView1.Enter += new System.EventHandler(this. dataGridView1_Enter);
this.dataGridView1.Leave += new System.EventHandler(this. dataGridView1_Leave);
this.dataGridView1.CellValidating += new System.Windows.Forms.DataGridViewCellValidatingEventHandler(this.Grid_CellValidating);
this.dataGridView1.SelectionChanged += new System.EventHandler(this.Grid_SelectionChanged);


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>