tags:

views:

34

answers:

2

Hello... I have a dataset which i bind to datagrid from wpf toolkit(forced to use .net 3.5).. I was ignorant as newbie to WPF and C# and didnt bind a collection of my objects,that would help a lot and would solve my problem!

So the cell is something like that

 <my:DataGridTemplateColumn.CellTemplate>
   <DataTemplate>
        <TextBlock Text="{Binding Length}" />
   </DataTemplate>
 </my:DataGridTemplateColumn.CellTemplate>

I would like to do something like

     <my:DataGridTemplateColumn.CellTemplate>
       <DataTemplate>
            <TextBlock Text="{Binding Length}" />
 <TextBlock Text="{Binding ????????}" />
       </DataTemplate>
     </my:DataGridTemplateColumn.CellTemplate>

Where ????? i would like to bind a value that depends from 2 values from the dataset and about 1000 other not in dataset... If i could bind to a method and provide these 2 as parameter .

The only solution i can think is adding 3 extra collumns to dataset .Then iterate each row and set the new's collumn cell with the calculated value.

A: 

Why don't you just adjust your code to bind to a collection, as you just say that this wil solve it

Forget my last answer.

Create a new collection just for that particular cell. Something like:

public Observablecollection<int> foo = new ObservableCollection<int>()


private void Calculation(int[] X, int[] Y)
{
    foo.Clear();
    int i;
    for(int index = 0; index < X.Length; index++)
    {
        //Calculation Like
        i = X[index] + y[index];
        foo.Add(i);
    }
}

You can add an event handler which calls calculation everytime the values in X and Y change. Finally bind foo to the cell

Maarten Van Genechten
Because if i do i would have to change many parts of the code....and should write new methods..
Parhs
A: 

Depending on what the other required information is, maybe you could use a MultiBinding with the two values and then access the additional information needed within the converter. Something like

<my:DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
        <TextBlock>
            <TextBlock.Text>
                <MultiBinding Converter="{StaticResource SomeTextMultiConverter}">
                    <Binding Path="Property1" />
                    <Binding Path="Property2" />
                </MultiBinding>
            </TextBlock.Text>
        </TextBlock>
    </DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
Meleak