if (this.chkSelectAll.IsChecked == true)
{
foreach (hl_whs_move_getCmdByTypeResult item in g.Items)
{
}
}
else
{
g.SelectedItems.Clear();
}全消可以,但全选好像不行哦...
各位高手帮忙看看..
解决方案 »
- BackgroundWorker调用控件的方法?
- (【孟子E章】) 求帮助
- 本人想做个软件用(C# VS2005) 遇到技术问题 希望大侠能给解决
- 水杯,欠你15分,另外有些问题想问问清楚。
- 变量的小问题......
- access数据库字段转换问题,有分送哦!(在线等)
- 怎么用Textbox显示数组输出?
- C#把窗体做进Dll,许多业务逻辑都写进Dll中,再由主窗体调用各个Dll中的窗体实现模块,这种做法有什么问题吗?
- vs2005打包问题,小弟请高人指点一下!
- 如何使下拉列表框初始化时不让第一个处于选中状态?
- dataadapter.update()中使用事务的问题?
- C#模式窗体的关闭事件
item.Selected = true;
foreach (ListViewItem item in g.Items)
{
item.Selected = true;
}报错哦:
Error 109 The event 'System.Windows.Controls.ListBoxItem.Selected' can only appear on the left hand side of += or -= D:\2dwms\WMS\Operation\CmdDist.xaml.cs 313 26 WMS
foreach (ListViewItem item in g.Items)
{
item.IsSelected = true;
}
如果设成IsSelected 则不会报说语法错..因为我的数据来源是LINQ里的存储过程来的,
List<hl_whs_move_getCmdByTypeResult> q = cmd.hl_whs_move_getCmdByType(0).ToList();
this.goodList4.DataContext = q;但会出现异常:Unable to cast object of type 'Avanti.dal.wmsDal.hl_whs_move_getCmdByTypeResult' to type 'System.Windows.Controls.ListViewItem'.
我和3楼刚才说的是WinForm中的Listview
嗯,,多谢哥们,现在的问题就是,listview的items为:hl_whs_move_getCmdByTypeResult
没法把它转成listviewitem,所以没法遍历,
{
foreach (ListViewItem it in this.listView1.Items)
it.Selected = true;
this.listView1.Focus();
}
else
{
this.listView1.SelectedItems.Clear();
}
另设置:
this.listView1.MultiSelect = true;
this.listView1.HideSelection = false;
想法跟我的是一样的,但现在的问题是:
lisviview 的datacontext为:hl_whs_move_getCmdByTypeResult类型,
无法转换为listviewItem...
对,selectall确实是可以选中,但效果不明显哦,,,背景色没有变,给人的感觉就是不知道有没有被选..
g.Focus();可以实现像全部选中的效果,但总感觉有些不对,,呵呵
你说的效果有些不对指的是Focus的虚线框吧~~可以使用
Keyboard.Focus(g.Items[0] as IInputElement); (使第一个item focus,这里可以根据需要设定不同的item得到焦点)
代替 g.Focus();当然事先要判断一下g中有没有Item,以免抛异常
{
//首先应得到 ListViewItem,所有可视UI 元素都继承了UIElement
UIElement u = ltv.ItemContainerGenerator.ContainerFromIndex(rowIndex) as UIElement;
if (u == null) return null; //然后在ListViewItem元素树中搜寻单元格
while ((u = (VisualTreeHelper.GetChild(u, 0) as UIElement)) != null)
if (u is GridViewRowPresenter) return VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(u, cellIndex), 0) as UIElement; return u;
}
private void CheckedCheckBox(ListView listView, bool bChecked)//选中或取消CheckBox
{
try
{
for (int i = 0; i < listView.Items.Count; i++)
{
CheckBox cb = (CheckBox)this.GetListViewCellControl(i, 0, listView);
cb.IsChecked = bChecked;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
仁兄,你的GetListViewCellControl方法返回null;