溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

datagrid使用

發(fā)布時間:2020-06-29 19:12:44 來源:網(wǎng)絡(luò) 閱讀:361 作者:kinwar 欄目:開發(fā)技術(shù)

/// <summary>

        /// 數(shù)據(jù)源

        /// </summary>

        private DataTable g_dtSource = new DataTable();


#region InitGrid 初始化Grid標(biāo)題信息

        /// <summary>

        /// 初始化Grid標(biāo)題信息

        /// </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 = "設(shè)備";

                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 = "上料狀態(tài)";

                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


//循環(huán)處理

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; 不能確認是這樣


                    //當(dāng)前棧位的物料 是否 與掃描的物料的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);            //設(shè)置選中

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

                } 


            }


向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI