0

Is it possible to combine a DataGridTextColumn and DataGridCheckBoxColumn into one column?

I have this class where I combine two columns values into one result:

public class ViewQuoteItemList
{
    public string Supplier { get; set; }
    public bool TrueFalse { get; set; }

    public string CheckBoxColumn
    {
        get { return string.Format("{0} {1}", Supplier, TrueFalse); }
    }
}

Then I bind one of the columns like this:

DataGridTextColumn columnFeedbackSupplier = new DataGridTextColumn();
columnFeedbackSupplier.Binding = new Binding("CheckBoxColumn");

I do not know how to bind/join a DataGridCheckBoxColumn with a DataGridTextColumn to display both the text and a checkbox in one column

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
CareTaker22
  • 1,260
  • 3
  • 18
  • 36

1 Answers1

3

DataGridTemplateColumn you can define Template for the same.

<DataGridTemplateColumn Header="ViewQuote">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Supplier}"/>
                <CheckBox IsChecked="{Binding TrueFalse}"/>
            </StackPanel>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
M. Schena
  • 2,039
  • 1
  • 21
  • 29
Abhinav Sharma
  • 443
  • 1
  • 4
  • 15
  • Great stuff! Thank you very much Abhinav! Also is there a way to bind a Tempelate column the same as you did in XAML, but do it in C# code? – CareTaker22 Feb 02 '16 at 11:11
  • [this](http://stackoverflow.com/questions/1754608/what-is-the-code-behind-for-datagridtemplatecolumn-and-how-to-use-it) and [this](http://stackoverflow.com/questions/8779893/create-datagridtemplatecolumn-through-c-sharp-code) are some links to get you started. – Abhinav Sharma Feb 02 '16 at 11:20
  • Also please don`t forget to mark it as answer.Thanks – Abhinav Sharma Feb 02 '16 at 11:21