But when i try to change to multiselect as below, i having problem on Guid, Please advise. My skeleton code not completed as below:-
foreach (ToolStripMenuItem
item in tsddbSegment.DropDown.Items) {
if (item.Checked ==
true) { productFamily = (Guid)item.Text;
//I stuck on this portion. How can i get Guid instead of value string. It maybe can call from Find segment method at helpers.cs file. But i dono how to call it & return into Guid. filterByProductFamily = (productFamily !=null && productFamily
!= Guid.Empty) ?
true :
false; }
}
micnie2020
Member
306 Points
524 Posts
From DropDown to MultiSelect
Apr 13, 2012 08:49 AM|LINK
Dear All,
When i am using combo box, my skeleton code work fine as this:-
Boolean filterByProductFamily = false;
Guid productFamily = Guid.Empty;
if (tscboProductFamily.ComboBox.SelectedValue != null) {
productFamily = (Guid)tscboProductFamily.ComboBox.SelectedValue;
filterByProductFamily = (productFamily !=null && productFamily != Guid.Empty) ? true : false;
}
productFamily will stored the Guid
But when i try to change to multiselect as below, i having problem on Guid, Please advise. My skeleton code not completed as below:-
foreach (ToolStripMenuItem item in tsddbSegment.DropDown.Items) {
if (item.Checked == true)
{
productFamily = (Guid)item.Text; //I stuck on this portion. How can i get Guid instead of value string. It maybe can call from Find segment method at helpers.cs file. But i dono how to call it & return into Guid.
filterByProductFamily = (productFamily !=null && productFamily != Guid.Empty) ? true : false; }
}
Helpers.cs
// Return dataset of options
public static List<SegmentItem> GetChoices()
{
// Establish reference to dataset
frmMain mainForm = (frmMain)Application.OpenForms["frmMain"];
DataSet1 dataset = mainForm.GetDataSet();
// Clear down existing list
possibleChoices.Clear();
// Add option 'All'
possibleChoices.Add(new SegmentItem("(All)"));
// Get distinct set of account managers refrenced in opportunity dataset
DataView tempView = new DataView(dataset.OpportunityElement, null, "productfamilyname", DataViewRowState.CurrentRows);
DataTable distinctSegments = tempView.ToTable(true, new string[] { "productfamilyname" });
// Quit now if no account managers
if (distinctSegments.Rows.Count == 0)
{
return possibleChoices;
}
// Create list of account manager options
foreach (DataRow segmentRow in distinctSegments.Rows)
{
SegmentItem segmentItem = new SegmentItem((string)segmentRow["productfamilyname"]);
possibleChoices.Add(segmentItem);
}
return possibleChoices;
}
// Find segment method
public static SegmentItem Find(String optionName)
{
return possibleChoices.Find(delegate(SegmentItem option) { return option.Name == optionName; });
}
}
Please Advise.
Thank you.
Regards,
Micheale
hiza808
Member
270 Points
75 Posts
Re: From DropDown to MultiSelect
Apr 15, 2012 09:28 PM|LINK
http://stackoverflow.com/questions/774587/multi-select-dropdown-list-in-asp-net
http://www.dotnetfunda.com/articles/article1591-multiselect-dropdown-in-aspnet-40-using-csharp.aspx
micnie2020
Member
306 Points
524 Posts
Re: From DropDown to MultiSelect
Apr 16, 2012 03:48 AM|LINK
I solved with solution by creating an function pass in a parameter and return the Guid.
Example function
public static Guid getProduct(string name)
{
frmMain mainForm = (frmMain)Application.OpenForms["frmMain"];
DataSet1 dataset = mainForm.GetDataSet();
// Get distinct set of Families referenced in opportunity dataset
DataView tempView = new DataView(dataset.OpportunityElement, null, "productfamilyname", DataViewRowState.CurrentRows);
DataTable distinctAProductFamily = tempView.ToTable(true, new string[] { "productfamilyname", "productfamily" });
Guid aPro = Guid.Empty;
// Create list of region options
foreach (DataRow aPFRow in distinctAProductFamily.Rows)
{
if ((string)aPFRow["productfamilyname"] == name)
{
aPro=(Guid)aPFRow["productfamily"];
}
}
return (aPro);
}
Thank you.
Regards,
Micheale