如何找到在列表視圖中選擇的項目我已經在列表視圖中管理這個在列表視圖分組項目,我有客戶表有列與當我們使用組列表視圖
category id
category name
categories
-----------
category name 1
category name 2
category name 3
price ranges
-----------
ALL
0-500
500-1000
我在上面所做的的任務,但是我有檢查列表視圖組選定項目的問題..
我的問題是,我們怎麼火成那樣,如果我選擇在列表視圖中第一組的第一個項目我想要做的事情況.. ..
如果我選擇在我想要做一些事情列表視圖中第二組的第一項...
,有些地方我必須使用事件中所選擇的項目文本.....
我如何找到檢查...
可以在此任意一個幫助.....
非常感謝....
,這是我的代碼
private void categorieslist()
{
lstviewcategories.View = View.Details;
lstviewcategories.Columns.Add(new ColumnHeader() { Width = lstviewcategories.Width - 20 });
lstviewcategories.HeaderStyle = ColumnHeaderStyle.None;
lstviewcategories.Sorting = SortOrder.Ascending;
lstviewcategories.Dock = DockStyle.None;
ListViewGroup categorygroup = new ListViewGroup("Category Types",HorizontalAlignment.Center);
lstviewcategories.Groups.Add(categorygroup);
var categorytypes = (from categories in abc.categories
select categories.category_Name).ToList();
lstviewcategories.Items.Add(new ListViewItem() { Text = "ALL", Group = categorygroup });
foreach (string item in categorytypes)
{
lstviewcategories.Items.Add(new ListViewItem() { Text = item.ToString(), Group = categorygroup });
}
ListViewGroup pricerangegroup = new ListViewGroup("Price Ranges", HorizontalAlignment.Center);
lstviewcategories.Groups.Add(pricerangegroup);
lstviewcategories.Items.Add(new ListViewItem() { Text = "ALL", Group = pricerangegroup });
lstviewcategories.Items.Add(new ListViewItem() { Text = "0-500", Group = pricerangegroup });
lstviewcategories.Items.Add(new ListViewItem() { Text = "500-1000", Group = pricerangegroup });
lstviewcategories.Items.Add(new ListViewItem() { Text = "1000+", Group = pricerangegroup });
}
編輯:
private void lstviewcategories_SelectedIndexChanged(object sender, EventArgs e)
{
// int index = 0;
if (lstviewcategories.SelectedItems.Count > 0 &&lstviewcategories.SelectedItems[0].Group.Name == "Category Types")
{
string text = lstviewcategories.SelectedItems[0].Text.ToString();
var categorywithids = (from categorytypes in abc.categories
where categorytypes.category_Name.Equals(text)
select categorytypes.category_Id).SingleOrDefault();
var productcategoty = from productswithcatgories in abc.product1
where productswithcatgories.category_Id.Equals(categorywithids)
select new
{
productid = productswithcatgories.product_Id, //0
productnam = productswithcatgories.product_Name, //1
productimage = productswithcatgories.product_Image, //2
productprice = productswithcatgories.product_Price,//3
productdescr = productswithcatgories.product_Description,//4
};
productbindingsource.DataSource = productcategoty;
productgridview.DataSource = productbindingsource;
productgridview.Columns[0].Visible = false;
productgridview.Columns[4].Visible = false;
}
}
將在此任何一個請幫助... –