我在 WpfDataGrid. I am adding values in datagrid's first column called
模型名称中有问题。下面我也给出了我的代码来显示问题。
所以我的问题是第一列将显示数据库中的值,而其他列可以写。所有值都将保存在某个数据库表中。当我使用datagrid.Items.Add(data);
then 它给出了第一列中的值,工作正常但是如果我开始在其他列中写入它会给出错误
“不允许编辑项目”。
这是我在 WPF 中的代码
<DataGrid HorizontalAlignment="Center"
Name="DeliveryGrid" IsReadOnly="False"
AutoGenerateColumns="False"
LoadingRow="DataGrid_LoadingRow"
Margin="0,85,0,0"
VerticalAlignment="Top"
Height="235"
Width="462">
<DataGrid.Columns>
<DataGridTextColumn Header="Model" Width="90" Binding="{Binding ModelName}" x:Name="ModelName" />
<DataGridTextColumn Header="Engine No" Width="90" x:Name="EngineNo" />
<DataGridTextColumn Header="Chasis No" Width="90" x:Name="ChasisNo" />
<DataGridTextColumn Header="Authority No" Width="90" x:Name="AuthorityNo" />
<DataGridTextColumn Header="Price" x:Name="Price" />
</DataGrid.Columns>
</DataGrid>
这是我的 C# 代码
public class BikesOrderObjects
{
public string ModelName { get; set; }
public int ModelID { get; set; }
public string BEngineNo { get; set; }
public string BChasisNo { get; set; }
public string BAuthorityNo { get; set; }
public double Price { get; set; }
public int qty { get; set; }
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
RST_DBDataContext conn = new RST_DBDataContext();
LoadDeliveryData();
}
private void LoadDeliveryData()
{
RST_DBDataContext conn = new RST_DBDataContext();
var BikesOrderData = conn.TblBikesOrdersDetails
.Where(TblBikesOrdersDetail => TblBikesOrdersDetail.BOId == 1)
.Select(TblBikesOrdersDetail => new
{
qty = TblBikesOrdersDetail.BQty,
ModelID = TblBikesOrdersDetail.ModelId,
ModelName = TblBikesOrdersDetail.TblBikeModel.ModelName
});
foreach (var item in BikesOrderData)
{
for (int i = 0; i < item.qty; i++)
{
var data = new BikesOrderObjects { ModelName = item.ModelName };
DeliveryGrid.Items.Add(data);
}
}
}