开发者

Locked DataGridView. Linq is a problem?

I get the collection from webservice:

var allPlaceHolders =
    from ph in new MyService().GetPlaceHolders()
    select new { Code = ph.Code, Name = ph.Name, Related = false };

dgPlaceHoldersAdd.DataSource = allPlaceHolders.ToList();

Designer.cs:

this.dgPlaceHoldersAdd.ColumnHeadersHeightSizeMode =
    System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgPlaceHoldersAdd.Location = new System.Drawing.Point(3, 54);
this.dgPlaceHoldersAdd.Name = "dgPlaceHoldersAdd";
this.dgPlaceHoldersAdd.RowHeadersVisible = false;
this.dgPlaceHoldersAdd.Size = new System.Drawing.Size(286, 151);
this.dgPlaceHoldersAdd.TabIndex = 15;

The problem is, that I can't changing value of checkBox column.

I has enabled AutoGeneratedColumns (In datagridview at start there is not any column)

ADDED:

This works funny: At first click id doesn't change value of checkbox column. At second work, and then start to work fine.

But...when I clicked at another row then row before change his values

It works like radiobutton...

 private void dgPlaceHold开发者_运维百科ersAdd_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {


            if (e.ColumnIndex == 2 && e.RowIndex > -1)
            {
                dgPlaceHoldersAdd.ReadOnly = false;
                dgPlaceHoldersAdd.CurrentRow.Cells[2].ReadOnly = false;

                 //dgPlaceHoldersAdd.EndEdit();

            }

        }


You create an anonymous object in your LINQ query. The classes C# generated behind the cover are immutable (=readonly). This means that your DataGridView can not change its value.

Try creating a custom object that is mutable and create that from within your LINQ query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜