zoukankan      html  css  js  c++  java
  • 子窗体的datagridview从主窗体的datagridview获取数据

    子窗体

    #region 增加地点
    
            private void button_AddHosAdr_Click(object sender, EventArgs e)
            {
                DlgAddPeBatchHspAdr dlgpbha = new DlgAddPeBatchHspAdr();
                dlgpbha.EvtRefresh += dlgpbha_EvtRefresh;
                //显示对话框
                dlgpbha.ShowDialog();
            }
    
            void dlgpbha_EvtRefresh(object sender, RefreshEventArgs e)
            {
                try
                {
                    if (sender != null)
                    {
                        List<pe_srvhosp> items = sender as List<pe_srvhosp>;//新增数据
                        if (items != null && items.Count > 0)
                        {
                            //原有数据
                            BindingCollection<pe_srvhosp> list = this.dataGridView_pe_srvhosp_list.DataSource as BindingCollection<pe_srvhosp>;
    
                            if (list != null && list.Count > 0)
                            {
                                List<pe_srvhosp> listsrvhosp = list.Intersect(items, new pe_srvhosp_Equality()).ToList();//重复数据
                                if (listsrvhosp != null && listsrvhosp.Count > 0)
                                {
                                    var chaji = items.Except(listsrvhosp, new pe_srvhosp_Equality()).ToList();//差集(A集合有,B没有)
                                    foreach (pe_srvhosp srv in chaji)
                                    {
                                        list.Add(srv);//新增数据去重后添加到原有数据
                                    }
                                    this.dataGridView_pe_srvhosp_list.DataSource = new BindingCollection<pe_srvhosp>(list);
                                    this.dataGridView_pe_srvhosp_list.Refresh();
                                }
                                else
                                {
                                    foreach (pe_srvhosp srv in items)
                                    {
                                        list.Add(srv);
                                    }
                                    this.dataGridView_pe_srvhosp_list.DataSource = list;
                                    this.dataGridView_pe_srvhosp_list.Refresh();
                                    int hosp_id = Convert.ToInt32(dataGridView_pe_srvhosp_list.Rows[0].Cells["Column_hosp_id"].Value); //获取第一行中列名为Column_hosp_id的值
    
                                    if (hosp_id <= 0)
                                    {
                                        dataGridView_pe_srvhosp_list.Rows.RemoveAt(0); //移除第一行数据
    
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "体检批次", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            #endregion

    主窗体

    DlgAddPeBatchHspAdr窗口
    //在最上方声明变量
     public event EventHandler<RefreshEventArgs> EvtRefresh;
    
    #region 保存体检地点
            private void button_save_Click(object sender, EventArgs e)
            {
                try
                {
                    if (dataGridView_main.SelectedRows != null && dataGridView_main.SelectedRows.Count > 0)
                    {
                        pe_srvhosp srvhosp = null;
                        List<pe_srvhosp> list = new List<pe_srvhosp>();
                        foreach (DataGridViewRow row in dataGridView_main.SelectedRows)
                        {
                            srvhosp = row.DataBoundItem as pe_srvhosp;
                            list.Add(srvhosp);
                        }
                        if (EvtRefresh != null)
                        {
                            EvtRefresh(list, null);
                        }
                        this.Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "增加医院", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            #endregion
  • 相关阅读:
    Android将TAB选项卡放在屏幕底部(转)
    unix进程间通信
    C优先级顺序(转)
    C/C++ 内存补齐机制
    Android Sqlite ORM 工具
    类型安全性测试
    反射手册笔记 2.程序集,对象和类型
    CLR笔记:15.委托
    反射手册笔记 4.创建对象
    反射手册笔记 1.灵活的编程方法
  • 原文地址:https://www.cnblogs.com/wmm-pcy/p/9752765.html
Copyright © 2011-2022 走看看