 |
|
คือผม จะ cast ให้ มันเช็ค การ select item ใน Listview ที่ชื่อ lsvProductList น่ะครับ ผมลองมาหลายวิธีแล้วอะครับ ตอนนี้ผมใช้การตัดตัวอักษรโดยใช้ SubString() ตัดข้อความแต่ละส่วนที่อยู่ใน lsvProdcutList.SelectedItemเอาอะ มันไม่เปนธรรมชาติไงไม่รู้ มันมีวิธีที่ มันเปนธรรมชาติกว่านี้ใหมอะครับ
รูป error :
code ส่วนที error อะครับ
ผมติดตรง จะทำไงให้มันโชว์ ข้อมูลที่ อยู่ใน IsvProductList.SelectedItem อะครับ
Code (C#)
void IsvProductList_MouseUp(object sender, MouseButtonEventArgs e)
{
try
{
var pd = (Database.Product)IsvProductList.SelectedItem;// เปน type Product มัน cast ได้เลย แต่มันไม่ไช่อะครับมันเปน tyye อะไรไม่รู้ ผมติดตรงนี้ จะทำไงให้มันโชว์ ข้อมูลที่ อยู่ใน IsvProductList.SelectedItem อะครับ
txbEditID.Text = pd.PID;
txtProductNameEditAfter.Text = pd.ProductName;
txbProductEditBefore.Text = pd.ProductName;
cboEditSize.SelectedIndex = Convert.ToInt16(pd.PID);
cboEditGroup.SelectedIndex = Convert.ToInt16(pd.GID);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private delegate void DelegateSub(IQueryable<object> product,
IQueryable<Database.ProductGroup> productGroup,
IQueryable<Database.ProductSize> productSize);
private void LongProcess()
{
object obj = new object();
lock (obj)
{
Thread.Sleep(301);
var pg = from g in db.ProductGroups select g;
var ps = from s in db.ProductSizes select s;
tempData = from p in db.Products
from s in db.ProductSizes
from g in db.ProductGroups
where p.SID == s.SID && p.GID == g.GID
select new { p.PID, p.ProductName, s.SizeName, g.ProductGroupName }; // <<<< มัน ทำการ new เป็น type ใหม่อะ
UpdateUI(tempData, pg, ps);
}
}
private void UpdateUI(IQueryable<object> product,
IQueryable<Database.ProductGroup> productGroup,
IQueryable<Database.ProductSize> productSize)
{
if (Dispatcher.Thread != Thread.CurrentThread)
{
Dispatcher.Invoke(new DelegateSub(UpdateUI), product, productGroup, productSize);
}
else
{
if (product.Count() > 0)
{
IsvProductList.ItemsSource = product.ToList();
Animations.Fade(IsvProductList);
IsvProductList.IsEnabled = true;
}
else
{
IsvProductList.ItemsSource = null;
}
if (productGroup.Count() > 0)
{
foreach (var pg in productGroup)
{
cboProductGroup.Items.Add(pg);
cboEditGroup.Items.Add(pg);
}
cboProductGroup.SelectedValuePath = "GID";
cboEditGroup.SelectedValuePath = "GID";
cboProductGroup.SelectedIndex = 0;
Animations.Fade(cboProductGroup);
cboProductGroup.IsEnabled = true;
}
else
{
return;
}
if (productSize.Count() > 0)
{
foreach (var ps in productSize)
{
cboProductSize.Items.Add(ps);
cboEditSize.Items.Add(ps);
}
cboProductSize.SelectedValuePath = "SID";
cboEditSize.SelectedValuePath = "SID";
cboProductSize.SelectedIndex = 0;
Animations.Fade(cboProductSize);
cboProductSize.IsEnabled = true;
}
else
{
return;
}
}
}
Tag : .NET, LINQ, C#, VS 2010 (.NET 4.x)
|
ประวัติการแก้ไข 2011-11-10 09:36:21 2011-11-10 09:37:02
|
 |
 |
 |
 |
Date :
2011-11-10 09:32:52 |
By :
Drewsn32 |
View :
1664 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |