C#-c# 程序问题 未将对象引用设置到对象的实例
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 检查项目
/// </summary>
private List<jcxm> jcxm = new List<jcxm>();
public List<jcxm> Jcxm
{
get { return jcxm; }
set { jcxm = value; }
}
/// <summary>
/// 检查套餐
/// </summary>
private List<jctc> jctc = new List<jctc>();
public List<jctc> Jctc
{
get { return jctc; }
set { jctc = value; }
}
/// <summary>
/// 检查项目赋值
/// </summary>
public void xm()
{
jcxm xm1 = new jcxm();
xm1.Xmmc = "肝功能";
xm1.Xmms = "肝功能体检";
xm1.Dj = 100;
jcxm xm2 = new jcxm();
xm2.Xmmc = "视力";
xm2.Xmms = "视力体检";
xm2.Dj = 50;
jcxm xm3 = new jcxm();
xm3.Xmmc = "脑核磁";
xm3.Xmms = "脑核磁体检";
xm3.Dj = 200;
Jcxm.Add(xm1);
Jcxm.Add(xm2);
Jcxm.Add(xm3);
}
/// <summary>
/// 绑定到dgv
/// </summary>
public void bdjh()
{
this.dgvXS.DataSource = new BindingList<jcxm>(this.jcxm);
}
/// <summary>
/// 项目下拉框
/// </summary>
public void xmxlk()
{
string[] mn = new string[jcxm.Count];
for(int i = 0;i< mn.Length;i++)
{
mn[i] = jcxm[i].Xmmc;
}
this.cboJCXM.DataSource = mn;
}
/// <summary>
/// 套餐名称赋值
/// </summary>
public void tc()
{
jctc tc1 = new jctc();
tc1.Tcm = "学生体检";
jctc.Add(tc1);
}
/// <summary>
/// 套餐下拉框
/// </summary>
public void tcjctc()
{
string[] mc = new string[jctc.Count];
for (int i = 0; i < mc.Length;i++ )
{
mc[i] = jctc[i].Tcm;
}
this.cboTCLB.DataSource = mc;
}
private void Form1_Load(object sender, EventArgs e)
{
//默认选中一行
this.dgvXS.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
this.label1.Text = "";
this.label2.Text = "";
xm();
tc();
xmxlk();
tcjctc();
xstc();
}
public void xstc()
{
jctc tc = null;
jcxm xm = null;
string tc1 = "学生体检";
foreach(jctc ft in jctc)
{
if(tc1.Equals(ft.Tcm))
{
tc = ft;
break;
}
}
tc.Jcxm.Clear();
string xmmc = "肝功能";
foreach(jcxm ft in jcxm)
{
if(xmmc.Equals(ft.Xmmc))
{
xm = ft;
break;
}
}
jcxm xm1 = null;
string xmmc2 = "视力";
foreach (jcxm ft in jcxm)
{
if (xmmc2.Equals(ft.Xmmc))
{
xm1 = ft;
break;
}
}
tc.Jcxm.Add(xm);
tc.Jcxm.Add(xm1);
}
private void btnTJ1_Click(object sender, EventArgs e)
{
string txmc1 = this.txtTCMC.Text.Trim();
jctc tc2 = new jctc();
tc2.Tcm = txmc1;
}
//public void tcbd(jctc tc0)
//{
// this.dgvXS.DataSource = new BindingList<jcxm>(tc0.Jcxm);
//}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般这个错误都是因为使用了值为NULL的引用类型,你最好看下是那句话出错了,那个地方应该使用了一个空的引用类型。