0

I've got a datagrid with a checkbox, name and email. On CheckboxChecked I want to copy the email into another list or string.

How do I get the specific value from the checked row?

private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
    object row = lbxCC1.SelectedItem;
    int columnIndex = lbxCC1.Columns.Single(c => c.Header.Equals("eMail")).DisplayIndex;
    String eMail = (lbxCC1.SelectedCells[columnIndex].Column.GetCellContent(row) as TextBlock).Text;
    MessageBox.Show(eMail);
}

Edit (09.09.2016): Maybe I should show you a bit more code.

public class Person
{
    public string Nachname { get; set; }
    public string Vorname { get; set; }
    public string eMail { get; set; }
    public string Abteilung { get; set; }

}
public static class PersonService
{
    public static List<Person> ReadFile(string filepath)
    {
        var lines = File.ReadAllLines(filepath);

        var data = from l in lines.Skip(1)
                   let split = l.Split(';')
                   select new Person
                   {
                       Nachname = split[1],
                       Vorname = split[2],
                       eMail = split[31],
                       Abteilung = split[4],
                   };

        return data.ToList();
    }
}

I call it with:

lbxCC1.DataContext = PersonService.ReadFile(@"C:\Test.csv");

As I'm building the columns from code behind, I guess I have to bind them aswell am I right?

Sorry for this, but I'm new to datagrids :-)

mykds
  • 63
  • 9

1 Answers1

0

I think this might help you:

Dim row As Data.DataRowView = DirectCast([yourDataGrid].SelectedItems(rowIndex), Data.DataRowView)

Then in your CheckBox_Checked Event:

private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
    MessageBox.Show(row("email"); 'Assuming the column name is email
}

This is IF your values are data-bound to the DataGrid.

ViVi
  • 4,339
  • 8
  • 29
  • 52
GaaTY
  • 118
  • 3
  • 12