温馨提示×

温馨提示×

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

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

datagrid使用

发布时间:2020-06-29 19:12:44 阅读:373 作者:kinwar 栏目:开发技术
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

/// <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++;

                } 

            }

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

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

AI

开发者交流群×