datagrid使用

发布时间:2020-06-29 19:12:44 作者:kinwar
来源:网络 阅读:357

/// <summary>

        /// 数据源

        /// </summary>

        private DataTable g_dtSource = new DataTable();


#region InitGrid 初始化Grid标题信息

        /// <summary>

        /// 初始化Grid标题信息

        /// </summary>

        private void InitGrid()

        {

            this.g_dtSource.Clear();

            this.g_dtSource.Columns.Add("DeviceCode", typeof(string)).ReadOnly = true;

            this.g_dtSource.Columns.Add("SlotName", typeof(string)).ReadOnly = true;

            this.g_dtSource.Columns.Add("MitemCode", typeof(string)).ReadOnly = true;

            this.g_dtSource.Columns.Add("LoadStatus", typeof(string)).ReadOnly = true;


            this.dgInfo.DataSource = this.g_dtSource;


            DataGridTableStyle dgtStyle = new DataGridTableStyle();

            if (this.dgInfo.TableStyles.Count == 0)

            {

                this.dgInfo.TableStyles.Add(dgtStyle);


                dgtStyle.GridColumnStyles[0].HeaderText = "设备";

                dgtStyle.GridColumnStyles[0].MappingName = "DeviceCode";

                dgtStyle.GridColumnStyles[0].NullText = "";

                dgtStyle.GridColumnStyles[0].Width = 50;


                dgtStyle.GridColumnStyles[1].HeaderText = "栈位";

                dgtStyle.GridColumnStyles[1].MappingName = "SlotName";

                dgtStyle.GridColumnStyles[1].NullText = "";

                dgtStyle.GridColumnStyles[1].Width = 60;


                dgtStyle.GridColumnStyles[2].HeaderText = "物料编码";

                dgtStyle.GridColumnStyles[2].MappingName = "MitemCode";

                dgtStyle.GridColumnStyles[2].NullText = "";

                dgtStyle.GridColumnStyles[2].Width = 60;


                dgtStyle.GridColumnStyles[3].HeaderText = "上料状态";

                dgtStyle.GridColumnStyles[3].MappingName = "LoadStatus";

                dgtStyle.GridColumnStyles[3].NullText = "";

                dgtStyle.GridColumnStyles[3].Width = 60;

            }

        }

        #endregion


#region 选中整行

        private void dgInfo_CurrentCellChanged(object sender, EventArgs e)

        {

            this.dgInfo.Select(this.dgInfo.CurrentRowIndex);

        }

        #endregion


//循环处理

for (int i = 0; i < this.g_dtSource.Rows.Count; i++)

            {                                                  


                if (this.g_dtSource.Rows[i]["SlotName"].ToString() == SloatName)

                {

                    bSloatName = true;

                    currMitemCode = this.g_dtSource.Rows[i]["MitemCode"].ToString();

                    //bool bEqualMitemCode = false;

                    //bEqualMitemCode = this.txtMitem.Text.IndexOf(currMitemCode) > 0; 不能确认是这样


                    //当前栈位的物料 是否 与扫描的物料的UID 一致  

                    if (ScanMitemCode == currMitemCode)

                    //if (bEqualMitemCode)

                    {

                        //匹配成功修改为Y

                        this.g_dtSource.Columns["LoadStatus"].ReadOnly = false;

                        this.g_dtSource.Rows[i]["LoadStatus"] = "Y";

                        this.dgInfo.Select(i);            //设置选中

                        this.txtMitem.Text = "";

                        this.txtSloatName.Text = "";

                        this.txtMitem.Focus();

                       

                    }

                    else

                    {

                        this.txtMitem.SelectAll();

                        this.SetMsg("上料表的物料和料盘的物料不一致!", Color.Red);

                        break;

                        //return;

                    }   

                    

                }


                if (this.g_dtSource.Rows[i]["LoadStatus"].ToString() == "Y")

                {

                    iFinishCnt++;

                } 


            }


推荐阅读:
  1. jQuery EasyUI之DataGrid使用示例
  2. struts与datagrid显示数据

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

信息 private 数据源

上一篇:8月顺利拿到OPPO公司Android架构师offer,一面+部长面

下一篇:Zabbix 中文汉化方法,与出现乱码解决办法

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》