Vb.net 如果使用Select New with()指定列名,则Gridview不允许编辑

Vb.net 如果使用Select New with()指定列名,则Gridview不允许编辑,vb.net,winforms,Vb.net,Winforms,当我在vb.net中使用以下命令将数据绑定到gridview时,它工作正常,可以编辑单元格,但当我声明列名称时,它不允许我编辑单元格值,这是它们的任何原因,谢谢 Dim bs As New BindingSource bs.DataSource = (From u In threeContext.dbContext.skechersDeliveries Where u.isprocessed = False Select u) bs.ResetBindings(Tr

当我在vb.net中使用以下命令将数据绑定到gridview时,它工作正常,可以编辑单元格,但当我声明列名称时,它不允许我编辑单元格值,这是它们的任何原因,谢谢

    Dim bs As New BindingSource


    bs.DataSource = (From u In threeContext.dbContext.skechersDeliveries Where u.isprocessed = False Select u)

    bs.ResetBindings(True)
    dgDeliverys.DataSource = bs
这是一个示例,我将如何删除列名而不是slect u,我将在下面列出一些内容

       Select New With
            {
             Leave.Id,
            Leave.Leave_Month,
             Leave.Leave_App_Date,
            Leave.Leave_From_Date, Leave.Leave_To_Date, Emp.EmplName, Leavetype.LeaveDesc, Leave.Leave_Day
            }
我正在使用以下选项

订单号 Dim bs作为新的BindingSource

    Dim cfglocation As Int16
    cfglocation = cfb.StoreLocation
    bs.DataSource = (From u In threeContext.dbContext.R3Delivery Where u.isprocessed = False AndAlso u.location = cfglocation
                    Select OrderNumber = u.ordernumber, BarCode = u.tagbarcode, Qty = u.qty, Processed = u.isprocessed, NotDelivered = u.isDelivered)




    bs.ResetBindings(True)
    dgDeliverys.DataSource = bs

    dgDeliverys.Columns(0).ReadOnly = True
    dgDeliverys.Columns(1).ReadOnly = True
    dgDeliverys.Columns(2).ReadOnly =true

第三列是qtry,它应该是可更改的,因为您看到它们的i在2处停止,但是当我声明上面的列名时,我不能再双击并直接编辑数据网格了

我认为您应该

Dim bs As New BindingSource


bs.DataSource = (From u In threeContext.dbContext.skechersDeliveries 
                 Where u.isprocessed = False 
                 Select New With{.ID = u.FieldThatMapsToID,
                                 .LeaveMonth = u.FieldThatMapsToLeaveMonth,
                                 .......
                                 .Leave_Day = u.FieldThatMapsToLeave_Day})

bs.ResetBindings(True)
dgDeliverys.DataSource = bs

请说明您是如何定义列的。您是如何声明您的列的。这就是我告诉您的,我是这样做的,但当我来编辑单元格项时,它不再绑定为内联编辑,单元格看起来是只读的。。。。看看你的代码,看起来数据来自几个表,对吗?不,只是那个抱歉,代码刚刚脱离网络,我不能给出真正的表结构company@MMych请参阅代码更改以解释无法相信这太难了如果不声明列名,您可以编辑吗?如果你能用这个方法。在datagrid中定义列时不要使用AutoGenerateColumns=true,在每个列中定义用户HeaderText。