IS Handlecreated Prop. È sempre falso per il controllo GridView in Dev Express
-
21-12-2019 - |
Domanda
La mia forma di Windows contiene DevExpress.XtraGrid.GridControl
su generacodictagcode in modo simile in modo simile c'è anche la 2a classe chiamata come Form1
.Su Form1 Sto caricando i dati dal database.Quando faccio doppio clic sulla riga della griglia si assegna a un modulo2.Sul Form2
Form1
Event ishandlecreated Prop è vero (gridControl1_DoubleClick
è ereditata da Form2
)
void gridControl1_DoubleClick(object sender, EventArgs e)
{
if (gridControl1.IsHandleCreated)
{
}
Form2 obj = new Form2();
obj.Display();
}
.
Quindi ho creato una proprietà come su Form1
public GridControl GridControl1
{
get { return gridControl1; }
}
.
Ma quando chiamo il display () Metodo di Form2 e controllare il Prop di ISHANDLECREED su Form2 è falso.
public void Display()
{
if (handleCreated)
{
}
}
.
Codice completo come sotto generacoloDetagcode
public partial class Form1 : Form
{
public GridControl GridControl1
{
get { return gridControl1; }
}
public bool handleCreated
{
get { return gridControl1.IsHandleCreated; }
}
public Form1()
{
InitializeComponent();
gridControl1.DataSource = CreateTable(20);
gridControl1.DoubleClick += gridControl1_DoubleClick;
}
void gridControl1_DoubleClick(object sender, EventArgs e)
{
if (gridControl1.IsHandleCreated)
{
}
Form2 obj = new Form2();
obj.Display();
}
private DataTable CreateTable(int rowCount)
{
DataTable table = new DataTable();
table.Columns.Add("String", typeof(string));
table.Columns.Add("Int", typeof(int));
table.Columns.Add("Date", typeof(DateTime));
for (var i = 0; i < rowCount; i++)
{
table.Rows.Add(string.Format("Row {0}", i), i, DateTime.Today.AddDays(i));
}
return table;
}
}
**Form2**
public class Form2 : Form1
{
public Form2()
{
}
public void Display()
{
if (handleCreated)
{
}
//Form1 obj = new Form1();
//if (obj.handleCreated)
//{
//}
}
}
.
in Form2 Handlecreated è sempre falso Non so perché? per favore aiutami
Soluzione
Questo perché il tuo oggetto form2
è solo inizializzato solo.Il controllo farà la sua maniglia solo dopo aver creato la finestra, che visualizza questo controllo.Quindi, è necessario chiamare form2.Show()
o form2.ShowDialog()
e dopo tale controllo per gridControl1.IsHandleCreated
.
Puoi semplicemente testare questo comportamento utilizzando questo codice:
Form2 obj = new Form2();
MessageBox.Show("Created: " + obj.handleCreated);
obj.Show();
MessageBox.Show("Shown: " + obj.handleCreated);
.