Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使datagrid列可编辑_C# - Fatal编程技术网

C# 如何使datagrid列可编辑

C# 如何使datagrid列可编辑,c#,C#,我想使DataGrid中的两列可编辑。我尝试将readonly更改为false,但没有帮助 那么,有人能告诉我我可以尝试的其他方法吗?或者这是不允许编辑的东西 谢谢 我转到DataDridView任务,在那个特定的专栏中,我将只读改为“false”。但这没有帮助。 是的,这是一个WinForm namespace Payroll { partial class AttendanceLog { /// <summary> /// Requ

我想使DataGrid中的两列可编辑。我尝试将readonly更改为false,但没有帮助

那么,有人能告诉我我可以尝试的其他方法吗?或者这是不允许编辑的东西

谢谢

我转到DataDridView任务,在那个特定的专栏中,我将只读改为“false”。但这没有帮助。 是的,这是一个WinForm

namespace Payroll
{
    partial class AttendanceLog
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
            this.label11 = new System.Windows.Forms.Label();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.btnShow = new System.Windows.Forms.Button();
            this.cmbMonth = new System.Windows.Forms.ComboBox();
            this.label6 = new System.Windows.Forms.Label();
            this.cmbYear = new System.Windows.Forms.ComboBox();
            this.btnClose = new System.Windows.Forms.Button();
            this.dgAttendanceLog = new System.Windows.Forms.DataGridView();
            this.btnSave = new System.Windows.Forms.Button();
            this.statusStrip1 = new System.Windows.Forms.StatusStrip();
            this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
            this.slno = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.empId = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.empName = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.workedDays = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.absentDays = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.weeklyOff = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.lateCominBy = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.earlyGoingBy = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.groupBox1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dgAttendanceLog)).BeginInit();
            this.statusStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // label11
            // 
            this.label11.AutoSize = true;
            this.label11.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label11.ForeColor = System.Drawing.SystemColors.ControlText;
            this.label11.Location = new System.Drawing.Point(14, 42);
            this.label11.Name = "label11";
            this.label11.Size = new System.Drawing.Size(49, 13);
            this.label11.TabIndex = 106;
            this.label11.Text = "Month :";
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.btnShow);
            this.groupBox1.Controls.Add(this.cmbMonth);
            this.groupBox1.Controls.Add(this.label11);
            this.groupBox1.Controls.Add(this.label6);
            this.groupBox1.Controls.Add(this.cmbYear);
            this.groupBox1.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.groupBox1.ForeColor = System.Drawing.Color.MidnightBlue;
            this.groupBox1.Location = new System.Drawing.Point(12, 12);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(688, 79);
            this.groupBox1.TabIndex = 108;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Select";
            // 
            // btnShow
            // 
            this.btnShow.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnShow.ForeColor = System.Drawing.Color.Black;
            this.btnShow.Location = new System.Drawing.Point(533, 34);
            this.btnShow.Name = "btnShow";
            this.btnShow.Size = new System.Drawing.Size(75, 33);
            this.btnShow.TabIndex = 108;
            this.btnShow.Text = "Show";
            this.btnShow.UseVisualStyleBackColor = true;
            this.btnShow.Click += new System.EventHandler(this.btnShow_Click);
            // 
            // cmbMonth
            // 
            this.cmbMonth.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmbMonth.FormattingEnabled = true;
            this.cmbMonth.Items.AddRange(new object[] {
            "Month",
            "Jan",
            "Feb",
            "Mar",
            "Apr",
            "May",
            "Jun",
            "Jul",
            "Aug",
            "Sep",
            "Oct",
            "Nov",
            "Dec"});
            this.cmbMonth.Location = new System.Drawing.Point(83, 34);
            this.cmbMonth.Name = "cmbMonth";
            this.cmbMonth.Size = new System.Drawing.Size(125, 21);
            this.cmbMonth.TabIndex = 104;
            // 
            // label6
            // 
            this.label6.AutoSize = true;
            this.label6.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label6.ForeColor = System.Drawing.SystemColors.ControlText;
            this.label6.Location = new System.Drawing.Point(283, 42);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(39, 13);
            this.label6.TabIndex = 107;
            this.label6.Text = "Year :";
            // 
            // cmbYear
            // 
            this.cmbYear.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmbYear.FormattingEnabled = true;
            this.cmbYear.Location = new System.Drawing.Point(341, 34);
            this.cmbYear.Name = "cmbYear";
            this.cmbYear.Size = new System.Drawing.Size(125, 21);
            this.cmbYear.TabIndex = 105;
            // 
            // btnClose
            // 
            this.btnClose.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnClose.ForeColor = System.Drawing.Color.Black;
            this.btnClose.Location = new System.Drawing.Point(625, 501);
            this.btnClose.Name = "btnClose";
            this.btnClose.Size = new System.Drawing.Size(75, 33);
            this.btnClose.TabIndex = 9;
            this.btnClose.Text = "Close";
            this.btnClose.UseVisualStyleBackColor = true;
            this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
            // 
            // dgAttendanceLog
            // 
            this.dgAttendanceLog.AllowUserToAddRows = false;
            dataGridViewCellStyle1.BackColor = System.Drawing.Color.LightCyan;
            this.dgAttendanceLog.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
            this.dgAttendanceLog.BackgroundColor = System.Drawing.Color.WhiteSmoke;
            this.dgAttendanceLog.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dgAttendanceLog.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.slno,
            this.empId,
            this.empName,
            this.workedDays,
            this.absentDays,
            this.weeklyOff,
            this.lateCominBy,
            this.earlyGoingBy});
            this.dgAttendanceLog.Location = new System.Drawing.Point(12, 107);
            this.dgAttendanceLog.Name = "dgAttendanceLog";
            this.dgAttendanceLog.RowHeadersVisible = false;
            this.dgAttendanceLog.Size = new System.Drawing.Size(688, 388);
            this.dgAttendanceLog.TabIndex = 109;
            this.dgAttendanceLog.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgAttendanceLog_CellDoubleClick);
            // 
            // btnSave
            // 
            this.btnSave.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnSave.ForeColor = System.Drawing.Color.Black;
            this.btnSave.Location = new System.Drawing.Point(544, 501);
            this.btnSave.Name = "btnSave";
            this.btnSave.Size = new System.Drawing.Size(75, 33);
            this.btnSave.TabIndex = 110;
            this.btnSave.Text = "Save";
            this.btnSave.UseVisualStyleBackColor = true;
            this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
            // 
            // statusStrip1
            // 
            this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripStatusLabel1});
            this.statusStrip1.Location = new System.Drawing.Point(0, 545);
            this.statusStrip1.Name = "statusStrip1";
            this.statusStrip1.Size = new System.Drawing.Size(711, 22);
            this.statusStrip1.TabIndex = 111;
            this.statusStrip1.Text = "statusStrip1";
            // 
            // toolStripStatusLabel1
            // 
            this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
            this.toolStripStatusLabel1.Size = new System.Drawing.Size(298, 17);
            this.toolStripStatusLabel1.Text = "Note : Please Single click on respective field for manual entry";
            // 
            // slno
            // 
            this.slno.HeaderText = "Sl No.";
            this.slno.Name = "slno";
            this.slno.Width = 50;
            // 
            // empId
            // 
            this.empId.HeaderText = "Emp. ID";
            this.empId.Name = "empId";
            this.empId.Width = 75;
            // 
            // empName
            // 
            this.empName.HeaderText = "Emp. Name";
            this.empName.Name = "empName";
            this.empName.Width = 125;
            // 
            // workedDays
            // 
            this.workedDays.HeaderText = "Worked Days";
            this.workedDays.Name = "workedDays";
            this.workedDays.ReadOnly = true;
            this.workedDays.Width = 75;
            // 
            // absentDays
            // 
            this.absentDays.HeaderText = "Absent Days";
            this.absentDays.Name = "absentDays";
            this.absentDays.ReadOnly = true;
            this.absentDays.Width = 75;
            // 
            // weeklyOff
            // 
            this.weeklyOff.HeaderText = "Weekly Off";
            this.weeklyOff.Name = "weeklyOff";
            this.weeklyOff.Width = 75;
            // 
            // lateCominBy
            // 
            this.lateCominBy.HeaderText = "Late Going By (in Days)";
            this.lateCominBy.Name = "lateCominBy";
            // 
            // earlyGoingBy
            // 
            this.earlyGoingBy.HeaderText = "Early Going By (in Days)";
            this.earlyGoingBy.Name = "earlyGoingBy";
            // 
            // AttendanceLog
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.Color.WhiteSmoke;
            this.ClientSize = new System.Drawing.Size(711, 567);
            this.ControlBox = false;
            this.Controls.Add(this.statusStrip1);
            this.Controls.Add(this.btnSave);
            this.Controls.Add(this.dgAttendanceLog);
            this.Controls.Add(this.btnClose);
            this.Controls.Add(this.groupBox1);
            this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Name = "AttendanceLog";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Attendance Log";
            this.Load += new System.EventHandler(this.AttendanceLog_Load);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dgAttendanceLog)).EndInit();
            this.statusStrip1.ResumeLayout(false);
            this.statusStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label label11;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.Button btnShow;
        private System.Windows.Forms.Button btnClose;
        private System.Windows.Forms.DataGridView dgAttendanceLog;
        private System.Windows.Forms.ComboBox cmbMonth;
        private System.Windows.Forms.Label label6;
        private System.Windows.Forms.ComboBox cmbYear;
        private System.Windows.Forms.Button btnSave;
        private System.Windows.Forms.StatusStrip statusStrip1;
        private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
        private System.Windows.Forms.DataGridViewTextBoxColumn slno;
        private System.Windows.Forms.DataGridViewTextBoxColumn empId;
        private System.Windows.Forms.DataGridViewTextBoxColumn empName;
        private System.Windows.Forms.DataGridViewTextBoxColumn workedDays;
        private System.Windows.Forms.DataGridViewTextBoxColumn absentDays;
        private System.Windows.Forms.DataGridViewTextBoxColumn weeklyOff;
        private System.Windows.Forms.DataGridViewTextBoxColumn lateCominBy;
        private System.Windows.Forms.DataGridViewTextBoxColumn earlyGoingBy;
    }
}
名称空间工资单
{
部分课堂出勤记录
{
/// 
///必需的设计器变量。
/// 
private System.ComponentModel.IContainer components=null;
/// 
///清理所有正在使用的资源。
/// 
///如果应释放托管资源,则为true;否则为false。
受保护的覆盖无效处置(布尔处置)
{
if(处理和(组件!=null))
{
组件。Dispose();
}
基地。处置(处置);
}
#区域Windows窗体设计器生成的代码
/// 
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
/// 
私有void InitializeComponent()
{
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1=新建System.Windows.Forms.DataGridViewCellStyle();
this.label11=new System.Windows.Forms.Label();
this.groupBox1=new System.Windows.Forms.GroupBox();
this.btnShow=new System.Windows.Forms.Button();
this.cmbMonth=new System.Windows.Forms.ComboBox();
this.label6=new System.Windows.Forms.Label();
this.cmbYear=new System.Windows.Forms.ComboBox();
this.btnClose=new System.Windows.Forms.Button();
this.dGatendanceLog=new System.Windows.Forms.DataGridView();
this.btnSave=new System.Windows.Forms.Button();
this.statusStrip1=new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabel1=新系统.Windows.Forms.ToolStripStatusLabel();
this.slno=new System.Windows.Forms.DataGridViewTextBoxColumn();
this.empId=new System.Windows.Forms.DataGridViewTextBoxColumn();
this.empName=new System.Windows.Forms.DataGridViewTextBoxColumn();
this.workedDays=new System.Windows.Forms.DataGridViewTextBoxColumn();
this.absentDays=new System.Windows.Forms.DataGridViewTextBoxColumn();
this.weeklyOff=new System.Windows.Forms.DataGridViewTextBoxColumn();
this.lateCominBy=new System.Windows.Forms.DataGridViewTextBoxColumn();
this.earlyGoingBy=new System.Windows.Forms.DataGridViewTextBoxColumn();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dGatendanceLog)).BeginInit();
this.statusStrip1.SuspendLayout();
这个.SuspendLayout();
// 
//标签11
// 
this.label11.AutoSize=true;
this.label11.Font=new System.Drawing.Font(“Tahoma”,8.25F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((字节)(0));
this.label11.ForeColor=System.Drawing.SystemColors.ControlText;
this.label11.Location=新系统图纸点(14,42);
this.label11.Name=“label11”;
this.label11.Size=新系统图纸尺寸(49,13);
this.label11.TabIndex=106;
this.label11.Text=“月:”;
// 
//groupBox1
// 
this.groupBox1.Controls.Add(this.btnShow);
this.groupBox1.Controls.Add(本月);
this.groupBox1.Controls.Add(this.label11);
this.groupBox1.Controls.Add(this.label6);
this.groupBox1.Controls.Add(this.cmbYear);
this.groupBox1.Font=new System.Drawing.Font(“Tahoma”,9.75F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((字节)(0));
this.groupBox1.ForeColor=System.Drawing.Color.MidnightBlue;
this.groupBox1.Location=新系统.图纸.点(12,12);
this.groupBox1.Name=“groupBox1”;
this.groupBox1.Size=新系统图纸尺寸(688,79);
this.groupBox1.TabIndex=108;
this.groupBox1.TabStop=false;
this.groupBox1.Text=“选择”;
// 
//btnShow
// 
this.btnShow.Font=新的System.Drawing.Font(“Tahoma”,8.25F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((字节)(0));
this.btnShow.ForeColor=System.Drawing.Color.Black;
this.btnShow.Location=新系统图点(533,34);
this.btnShow.Name=“btnShow”;
this.btnShow.Size=新系统图纸尺寸(75,33);
this.btnShow.TabIndex=108;
this.btnShow.Text=“显示”;
this.btnShow.UseVisualStyleBackColor=true;
this.btnShow.Click+=新建System.EventHandler(this.btnShow\u Click);
// 
//每月
// 
this.cmbMonth.Font=new System.Drawing.Font(“Tahoma”,8.25F,System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point,((字节)(0)));
this.cmbMonth.FormattingEnabled=true;
此.cmbMonth.Items.AddRange(新对象[]{
“月”,
“简”,
“二月”,
“三月”,
“四月”,
“五月”,
“六月”,
“七月”,
“八月”,
“九月”,
“十月”,
“11月”,
“Dec”});
this.cmbMonth.Location=新系统图点(83,34);
this.cmbMonth.Name=“cmbMonth”;
this.cmbMonth.Size=新系统图纸尺寸(125,21);
this.cmbMonth.TabIndex=104;
// 
//标签6
//
public class Person
{
  public string Name { get; set; }
  public string EmpId { get; set; }
}

public MainForm()
{
  InitializeComponent();

  // bind column to property of person
  empName.DataPropertyName = "Name";
  empId.DataPropertyName = "EmpId";

  // set our bindinglist of persons as datasource
  var bindingList = new BindingList<Person>();
  bindingList.Add(new Person(){ Name = "John", EmpId = "12345" });
  bindingList.Add(new Person(){ Name = "David", EmpId = "12346" });
  dgAttendanceLog.DataSource = bindingList;
}