On my user control I have a list companies in a datagridview. When a company is selected I currently get the company information. Most of the information I can pull directly from my Company object and set the label value like so. lblWebsiteValue.Text = company.CompanyWebsite.
My issue now is how to handle the company phone numbers? Right now in my Company object I have a companyPhone entry that is of type DataRowCollection. I did this because a company will most likely have at least one business number, and one fax number, possible more.
Each phone row will have the following columns: phoneType, phoneNumber, ext. the phoneType and phoneNumber cannot be null.
I would want the in formation to display like this How do I do this?
Business: 123.123.1234 Ext 103
Fax: 123.123.1235
Here is my method that builds the company details. Currently only the first line displays
/// <summary>
/// Builds and displays the currently selected company details.
/// </summary>
private void buildCompanyDetails()
{
Company company = Company.getCompany((Int16)dataGridView1.Rows[((CurrencyManager)BindingContext[dataGridView1.DataSource]).Position].Cells[0].Value, out company);
lblCompanyNameValue.Text = company.CompanyName;
lblIndustryTypeValue.Text = company.CompanyIndustry;
lblWebsiteValue.Text = company.CompanyWebsite;
lblStatusValue.Text = company.CompanyStatus;
pnlPhone.Controls.Clear();
Label newItem = new Label();
foreach (DataRow phoneDataRow in company.CompanyPhone)
{
string[] phoneDetails = new string[phoneDataRow.ItemArray.Count()];
int columnIndex = 0;
newItem = new Label();
newItem.Width = 200;
StringBuilder stringBuilder = new StringBuilder();
foreach (object column in phoneDataRow.ItemArray)
{
phoneDetails[columnIndex] = Convert.ToString(column);
if(phoneDetails[columnIndex] != null && phoneDetails[columnIndex].Length > 0)
{
stringBuilder.Append(phoneDetails[columnIndex]);
stringBuilder.Append(" ");
}
columnIndex++;
}
newItem.Text = stringBuilder.ToString();
pnlPhone.Controls.Add(newItem);
}
}