Create class Email
:
public class Email
{
public Email(string email)
{
Address = email;
int index = email.IndexOf('@');
UserName = email.Substring(0, index);
Domain = email.Substring(index + 1);
}
public string Address { get; private set; }
public string UserName { get; private set; }
public string Domain { get; private set; }
}
And data-bind your grid to instances of this class:
var emails = from line in File.ReadLines(fileName)
select new Email(line);
grid.DataSource = emails.ToList();
If you need first column to be named Email
, then add columns manually and provide names of email class properties as DataPropertyName
for each column.
UPDATE: There is already existing class MailAddress
in System.Net.Mail namespace which you can use for same purpose:
var emails = from line in File.ReadLines(fileName)
select new MailAddress(line);
It has properties Address
, User
and Host
which serve your needs.