1
Answer

Close() Dispose()

Administrator

Administrator

22y
1.6k
1
Hi Guys, i've got a Form that i call and in the constructor it does some db processing, in some cases the db will return a null row so rather than show the form i want to display a message "Cannot find bal bal" and then Close/Dispose the form before it shows. it works fine except that the Close() methos is ignored and the form always shows. i tried dispose and again it continue exceuting until an exception, cannot access disposed resource.... public Form() { try { DataTable tbl = DB.GetData(); if(tbl.Rows.Count>0) { //Do As Normal } else { Close(); } //do some more processing } } but the close call never takes effect it continues on and does more processing.. has anyone seen this before, kind regards michael
Answers (1)
0
Administrator
Admin 2.3k 1.3m 22y
Create a private bool variable. In the constructor set the variable to true or false based on the row count. In the forms load event check the variable. Call the forms Close method if needed. You assign a method in your form to the load event in the InitializeComponent() like so: this.Load += new System.EventHandler(this.MyLoadHandler); here is the method private void MyLoadHandler(object sender, System.EventArgs e) { if(NoRows == true) { this.Close(); } }