With this code (listApplications is a ListView control):
private void ShowApplicationPropertiesForm() {
String FullPath = String.Empty;
String Title = String.Empty;
String Description = String.Empty;
Boolean Legacy = false;
Boolean Production = false;
Boolean Beta = false;
MyCustomListViewItemDescendant lvi = (MyCustomListViewItemDescendant)listApplications.SelectedItems[0];
FullPath = lvi.ExePath;
Title = lvi.Text;
Description = lvi.ToolTipText;
ApplicationProperties ap = new ApplicationProperties(
FullPath,
Title,
Description,
Legacy,
Production,
Beta);
ap.Show();
}
//overloaded form constructor
public ApplicationProperties(String AFullPath, String ATitle, String ADescription, Boolean ALegacy, Boolean AProduction, Boolean ABeta) {
this.Text = String.Format("{0} Properties", ATitle);
textBoxFullPath.Text = AFullPath;
textBoxTitle.Text = ATitle;
textBoxDescription.Text = ADescription;
checkBoxLegacy.Checked = ALegacy;
checkBoxProduction.Checked = AProduction;
checkBoxBeta.Checked = ABeta;
}
…I’m getting, “System.NullReferenceException was unhandled
Message=Object reference not set to an instance of an object.”
Stepping through it, the line that bombs is:
textBoxFullPath.Text = AFullPath;
textBoxFullPath is a Textbox on a form; AFullPath has a valid value of the sort: “Q:\What\AreYou\Gonna\Do\BabyBlue.exe”
Updated:
Partially solved.
It was the old “Premature Assignment” problem. By moving the assignments from the constructor to the Load() event, it no longer bombs (code below).
HOWEVER, now nothing is displaying on the form at runtime…???!?
public partial class ApplicationProperties : Form {
String _fullPath = String.Empty;
String _title = String.Empty;
String _description = String.Empty;
Boolean legacy = false;
Boolean production = false;
Boolean beta = false;
public ApplicationProperties() {
InitializeComponent();
}
public ApplicationProperties(String AFullPath, String ATitle, String ADescription, Boolean ALegacy, Boolean AProduction, Boolean ABeta) {
_fullPath = AFullPath;
_title = ATitle;
_description = ADescription;
legacy = ALegacy;
production = AProduction;
beta = ABeta;
this.CenterToScreen();
}
private void ApplicationProperties_Load(object sender, EventArgs e) {
//this.Text = String.Format("{0} Properties", _title);
Text = String.Format("{0} Properties", _title);
textBoxFullPath.Text = _fullPath;
textBoxTitle.Text = _title;
textBoxDescription.Text = _description;
checkBoxLegacy.Checked = legacy;
checkBoxProduction.Checked = production;
checkBoxBeta.Checked = beta;
}
Updated again:
Adding “InitializeComponent();” to the overloaded constructor did the trick – thanks, SW!
I think the designer always calls the parameterless constructor, so I’ve gravitated to no trying to make my own constructors for WinForm Forms.
See my suggestions to tweak below – if you don’t get to where you want, let me know and I’ll update.