Import Excel to Datagridview

I am posting a solution for both Excel 2003 and Excel 2007+. You are missing ‘ in Extended Properties For Excel 2003 try this private void button1_Click(object sender, EventArgs e) { String name = “Items”; String constr = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” + “C:\\Sample.xls” + “;Extended Properties=”Excel 8.0;HDR=YES;”;”; OleDbConnection con = new OleDbConnection(constr); OleDbCommand oconn = new … Read more

How to prevent going to next row after editing a DataGridViewTextBoxColumn and pressing EnterKey?

I tried this for changing the Enter behaviour for your Grid by inheriting a customcolumn from Textbox column and overriding the below event protected override bool ProcessDialogKey(Keys keyData) { if (keyData == Keys.Enter) return base.ProcessDialogKey(Keys.Tab); else return base.ProcessDialogKey(keyData); } So instead of the Enter Key being sent it emulates the action for Tab which will … Read more

How to create a Button that can send keys to a control without stealing the focus – Virtual Keyboard

Non-Selectable Button to Send Key like Virtual Keyboard It’s enough to make a non-selectable button and then handle it’s click event and send key. This way these buttons can work like virtual keyboard keys and the focus will remain on the control which has focus while it sends the key to the focused control. public … Read more

DataGridView changing cell background color

Simply create a new DataGridViewCellStyle object, set its back color and then assign the cell’s style to it: DataGridViewCellStyle style = new DataGridViewCellStyle(); style.BackColor = Color.FromArgb(((GesTest.dsEssais.FMstatusAnomalieRow)row.DataBoundItem).iColor); style.ForeColor = Color.Black; row.Cells[color.Index].Style = style;

DataGridView not showing properites of objects which implement ICustomTypeDescriptor

[*] DataGridView looks at the list version of metadata; the rules for this are… complex: if the data-source implements IListSource, GetList() is evaluated and used as the data-source (continue at 2) if the data-source implements ITypedList, GetProperties() is used to obtain metadata (exit) if a typed (non-object) indexer can be found (i.e. public T this[int … Read more