欢迎来到代码驿站!

.NET代码

当前位置:首页 > 软件编程 > .NET代码

绑定winform中DataGrid

时间:2021-01-04 16:14:30|栏目:.NET代码|点击:

复制代码 代码如下:

this.dgTankView.Columns["ID"].DataPropertyName = "ID";
            this.dgTankView.Columns["TankName"].DataPropertyName = "Name";
            this.dgTankView.Columns["Area"].DataPropertyName = "Area";
            this.dgTankView.Columns["Type"].DataPropertyName = "Type";
            this.dgTankView.Columns["Status"].DataPropertyName = "Status";
            this.dgTankView.Columns["Material"].DataPropertyName = "Material";
            this.dgTankView.Columns["MaterialCategory"].DataPropertyName = "MaterialCategory";
            this.dgTankView.Columns["MaxLevel"].DataPropertyName = "MaxLevel";
            this.dgTankView.Columns["MinLevel"].DataPropertyName = "MinLevel";
            this.dgTankView.Columns["MaxCapacity"].DataPropertyName = "MaxCapacity";
            this.dgTankView.Columns["MinCapacity"].DataPropertyName = "MinCapacity";
            this.dgTankView.Columns["Code"].DataPropertyName = "Code";

            ////set columns width
            //this.dgTankView.Columns["MaterialCategory"].Width = 80;
            //this.dgTankView.Columns["Material"].Width = 240;
            //this.dgTankView.Columns["TankName"].Width = 100;
            //this.dgTankView.Columns["Area"].Width = 80;
            //this.dgTankView.Columns["MaxLevel"].Width = 100;
            //this.dgTankView.Columns["MinLevel"].Width = 100;
            //this.dgTankView.Columns["MaxCapacity"].Width = 100;
            //this.dgTankView.Columns["MinCapacity"].Width = 100;
            //this.dgTankView.Columns["Type"].Width = 60;

            //this.dgTankView.Columns["Status"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

  this.dgTankView.AutoGenerateColumns = false;
            this.dgTankView.DataSource = tankviews;
            int rowCount = dgTankView.RowCount;
            if (SelectedIndex < rowCount || SelectedIndex >= rowCount)
            {
                this.dgTankView.Rows[0].Selected = true;
            }
            else
            {
                this.dgTankView.Rows[this.SelectedIndex].Selected = true;
            }


  for (int i = 0; i < dgrdSelectedMaterial.RowCount; i++)
            {
                if (decimal.Parse(dgrdSelectedMaterial.Rows[i].Cells["ColumnSelectedMinRatio"].Value.ToString()) > decimal.Parse(dgrdSelectedMaterial.Rows[i].Cells["ColumnSelectedMaxRatio"].Value.ToString()))
                {
                    MessageUtil.Info(string.Format(Config.MessageManager[MessageGroupHelper.FormatToName((int)MessageGroup.Client), "1959"].ToString(), dgrdSelectedMaterial.Rows[i].Cells["ColumnSelectedName"].Value.ToString()));
                    return false;
                }
            }


RowHeardersVisible=false
Selection Mode=Full row Select
ColumnHeaderDefault=alignCenter

///高
dgrdStaticTank.ColumnHeadersHeight = 40;
dgrdBlendMaterialQuality.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;

宽:
  dgrdBlendMaterial.AutoGenerateColumns = false;
            dgrdBlendMaterial.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dgrdBlendMaterial.Columns["ColumnMaterialTankName"].Width = 80;

----------------------------------------------------------

this.dataGridView1.CurrentCell.Value;  //当前处于活动状态的单元格的值

this.dataGridView1.CurrentCell.RowIndex;//当前处于活动状态的单元格所在的行

this.dataGridView1.CurrentCell.ColumnIndex;//当前处于活动状态的单元格所在的列

this.dataGridView1.Rows[5].Cells[3].Value;//位于第6行第4列的单元格的值
DataGridView[col,row].Value=obj;

   ControlUtil.SetDataGridViewStyleForMasterData(dgrdBlendMaterial);
            dgrdBlendMaterial.AutoGenerateColumns = false;
            dgrdBlendMaterial.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dgrdBlendMaterial.Columns["ColumnMaterialName"].Width = 200;

      ucPagingTank.DataBindings.Add("PageIndex", tankListModel, "PageIndex", true, DataSourceUpdateMode.Never);

-----某列的显示格式----
dgrdTank.Columns["ColumnTimeStamp"].DefaultCellStyle.Format = Config.AppConfig.DateTimeFormat;

---取得选中某列的值-----
strCurRoleID = dgrdRoleList.SelectedRows[0].Cells[0].FormattedValue.ToString();


上一篇:ASP.NET微信公众号之用户分组管理web页面

栏    目:.NET代码

下一篇:浅谈ASP.NET Core 中jwt授权认证的流程原理

本文标题:绑定winform中DataGrid

本文地址:http://www.codeinn.net/misctech/40467.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有