這裏我在wpfwin.xaml DataGrid中值(從數據上下文綁定源)。我想收集名單「Challan_No」的價值,但我不能做到這一點..please幫我如何閱讀檢查行單元格中的WPF DataGrid中使用C#
<DataGridTextColumn Header="Chalaan ID" Width="Auto" Binding="{Binding Id, Mode=OneWay}"/>
<DataGridTextColumn Header="Challan No" Width="Auto" Binding="{Binding Challan_No, Mode=OneWay}" IsReadOnly="True"/>
<DataGridTextColumn Header="Company" Width="Auto" Binding="{Binding Organization_Name, Mode=OneWay}"/>
<DataGridTextColumn Header="Client" Width="Auto" Binding="{Binding Organization, Mode=OneWay}"/>
<DataGridTextColumn Header="Date" Width="Auto" Binding="{Binding Date, Mode=OneWay}"/>
<DataGridTemplateColumn Header="select" Width="100" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox x:Name="ckselect" ></CheckBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
在這裏,我嘗試了一些代碼來獲取它的.cs頁
ArrayList list = new ArrayList();
for (int i = 0; i < myGrid.Items.Count; i++)
{
CheckBox mycheckbox = myGrid.Columns[5].GetCellContent(myGrid.Items[i]) as CheckBox;
if (mycheckbox.IsChecked == true)
{
int inde = this.myGrid.SelectedIndex;
DataRowView drv = (DataRowView)myGrid.Items[inde];
object ch = drv[1];
list.Add(ch);
}
}
如何啓用複選框選中 – 2014-12-11 10:19:24
你的意思是讓DataGridCheckBoxColumn的器isChecked默認值爲true? – Usama 2014-12-11 10:26:41
我實現您的代碼在我的網頁BU山雀無法使選擇它們 – 2014-12-11 10:35:10