datagrid使用

/// <summary>app

        /// 数据源ide

        /// </summary>this

        private DataTable g_dtSource = new DataTable();编码


#region InitGrid 初始化Grid标题信息string

        /// <summary>it

        /// 初始化Grid标题信息io

        /// </summary>class

        private void InitGrid()object

        {循环

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

                } 


            }

相关文章
相关标签/搜索