I want to somehow pass the reference (from form1.cs class) and access the reference of datagridview1 which is used only in Form1.cs in my declaration of customdatagridview . The reason is that in every form of my windows application , there will be a new Datagridview (all with different names) , and their reference would be used for some purpose by this custom datagridview . Is it possible to do it . If not , what should be the alternative.
public partial class smartdatagridview : DataGridView { public smartdatagridview() { InitializeComponent(); } private TextBox textBox; protected override void OnEnter(EventArgs e) { base.OnEnter(e); CurrentCell = this[0, 0]; BeginEdit(true); } protected override void OnEditingControlShowing(DataGridViewEditingControlShowingEventArgs e) { base.OnEditingControlShowing(e); if (CurrentCell.ColumnIndex == 0 && e.Control is TextBox) { textBox = (TextBox)e.Control; textBox.TextChanged -= Text_Changed; textBox.KeyDown -= Key_down; textBox.Enter -= Key_Enter; textBox.TextChanged += Text_Changed; textBox.KeyDown += Key_down; textBox.Enter +=Key_Enter; } else { textBox = null; } } protected override void OnCellEndEdit(DataGridViewCellEventArgs e) { base.OnCellEndEdit(e); if (textBox != null) { textBox.TextChanged -= Text_Changed; textBox.KeyDown -= Key_down; textBox.Enter -= Key_Enter; textBox = null; } if (this.CurrentCell.ColumnIndex == 0) { if (dataGridView1.Rows.Count > 0) ***// error*** { this.CurrentCell.Value = dataGridView1.SelectedRows[0].Cells[1].Value.ToString(); ***// error*** dataGridView1.Visible = false; ***// error*** } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)