Hi guys,
I have a collection in a class, and I have another class and I need to reference this collection in another class. How can I do that? This is my code:
I have a collection in a class, and I have another class and I need to reference this collection in another class. How can I do that? This is my code:
Code:
namespace CashRegister.Reports
{
public partial class CustLevelReportPrint : Window
{
public CustLevelReportPrint(string zipfrom, string zipto, int catId,
string custNumber, bool sortbyzip, bool sortbyname, bool sortbycat)
{
InitializeComponent();
Customers = CustLabels.LoadDatas(zipfrom, zipto, catId, <--- HERE I FILL MY COLLECTION
custNumber, sortbyzip, sortbyname, sortbycat);
this.DataContext = this;
}
public List<CustLabels> Customers { get; set; } <--- HERE I DECLARE THE COLLECTION
}
public class CustLabelConverter : IValueConverter
{
int i ,j = 0;
StringBuilder Line1 = new StringBuilder();
StringBuilder Line2 = new StringBuilder();
StringBuilder Line3 = new StringBuilder();
StringBuilder theLabelText = new StringBuilder();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{ <--- HERE I NEED TO REFERENCE THE COLLECTION
E.G i = Customers.Count;
string cad;
if (value == null || !(value is CustLabels))
{
if (theLabelText.ToString() == string.Empty)
return Binding.DoNothing;
else
return theLabelText.ToString();
}
if (i < 3)
{
CustLabels val = value as CustLabels;
cad = (val.Name.ToString().Length > 50 ? val.Name.ToString().Substring(0, 50) : val.Name.ToString();
Line1.AppendFormat(cad + "\t");
cad = (val.Address.ToString().Length > 50 ? val.Address.ToString().Substring(0, 50) : val.Address.ToString());
Line2.AppendFormat(cad + "\t");
cad = val.City.ToString().Trim() + ", " + val.State.ToString().Trim() + ", " + val.ZipCode.ToString().Trim();
cad = (cad.Length > 50 ? cad.ToString().Substring(0, 50) : cad.ToString().PadRight(50));
Line3.AppendFormat(cad + "\t");
i++;
if (i == 3)
{
i = 0;
theLabelText.AppendFormat("{0}" + Line1.ToString(), Environment.NewLine);
theLabelText.AppendFormat("{0}" + Line2.ToString(), Environment.NewLine);
theLabelText.AppendFormat("{0}" + Line3.ToString(), Environment.NewLine);
Line1.Remove(0, Line1.Length);
return theLabelText.ToString();
}
else
return Binding.DoNothing;
}
else
{
i = 0;
return theLabelText.ToString();
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return Binding.DoNothing;
}
}
Comment