DataGrid中的DataGridCheckBoxColumn用法 ..

<my:DataGridCheckBoxColumn Header="选中" x:Name="checkBox" IsReadOnly="False" CanUserResize="False" Width="" />

 private void btnDeleteNote_Click(object sender, RoutedEventArgs e)
{
for (int i = ; i < this.dgvNotesManage.Items.Count; i++)
{
var cntr = dgvNotesManage.ItemContainerGenerator.ContainerFromIndex(i);
DataGridRow ObjROw = (DataGridRow)cntr;
if (ObjROw != null)
{
FrameworkElement objElement = dgvNotesManage.Columns[].GetCellContent(ObjROw);
if (objElement != null)
{
if (objElement.GetType().ToString().EndsWith("CheckBox"))
{
System.Windows.Controls.CheckBox objChk = (System.Windows.Controls.CheckBox)objElement;
if (objChk.IsChecked == true)
{
//if (System.Windows.MessageBox.Show("确认删除此公告?", "确认公告删除", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
//{
string noteId = ((DataRowView)this.dgvNotesManage.Items[i])["NoteId"].ToString();
string sql = string.Format("DELETE FROM OODBS_NoteUser WHERE NoteId='{0}'", noteId);
bool flag2 = new CommunicationShare.Proxy.ProxyClient().DeleteNoteObject(sql);
sql = string.Format("DELETE FROM OODBS_Notes WHERE NoteId='{0}'", noteId);
bool flag1 = new CommunicationShare.Proxy.ProxyClient().DeleteNote(sql);
}
}
}
}
}
BindNoteManage();
} //单击某行即选中那行的CheckBox private void dgvNotesManage_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var cntr = dgvNotesManage.ItemContainerGenerator.ContainerFromIndex(dgvNotesManage.SelectedIndex);
DataGridRow ObjROw = (DataGridRow)cntr;
if (ObjROw != null)
{
FrameworkElement objElement = dgvNotesManage.Columns[].GetCellContent(ObjROw);
if (objElement != null)
{
if (objElement.GetType().ToString().EndsWith("CheckBox"))
{
System.Windows.Controls.CheckBox objChk = (System.Windows.Controls.CheckBox)objElement;
if (objChk.IsChecked == true)
{
objChk.IsChecked = false;
}
else
objChk.IsChecked = true;
}
}
}
}
上一篇:js架构设计模式——MVVM模式下,ViewModel和View,Model有什么区别


下一篇:WPF实战案例-MVVM模式下在Xaml中弹出窗体