Mohan
Mohan

Reputation: 969

How to bind data row by row in devexpress datagrid for silverlight 4

I want to bind images based on data in Devexpress datagrid for silverlight. Is there any event like rowdatabound in devexpress grid for silverlight. any help will be appreciated. based on database boolean value I want to show required images.

<dxg:GridControl x:Name="gvPaymentCodes" Width="Auto" Grid.Row="2" Grid.Column="0" CustomUnboundColumnData="gvPaymentCodes_CustomUnboundColumnData">
        <dxg:GridControl.Columns>
            <dxg:GridColumn Name="gridColumn1" ReadOnly="True" FieldName="PaymentCode" Header="Current Payment Codes" Width="250" />
            <dxg:GridColumn Header="Required" Name="colImageRequired">
                <dxg:GridColumn.CellTemplate>
                    <DataTemplate>
                        <Canvas>
                            <Image x:Name="imgRequired" Source="{Binding}" Loaded="imgRequired_Loaded"></Image>
                        </Canvas>
                    </DataTemplate>
                </dxg:GridColumn.CellTemplate>
            </dxg:GridColumn>    

Thanks

Upvotes: 0

Views: 3310

Answers (2)

DmitryG
DmitryG

Reputation: 17850

I suggest you use custom value converter or custom cell template selector as it demonstated in the following articles:

Upvotes: 1

Niranjan Singh
Niranjan Singh

Reputation: 18290

you can use custom template .. and can change it conditionally as:

public class RowCellTemplateSelector : DataTemplateSelector {
        public override DataTemplate SelectTemplate(object item, DependencyObject container) {
            GridCellData cellData = item as GridCellData;
            FrameworkElement presenter = container as FrameworkElement;
            if (cellData != null && presenter != null) {
                if (cellData.Column.FieldName != "UnitPrice")
                    return base.SelectTemplate(item, container);
                if(Convert.ToDouble(cellData.Value) > 20)
                    return RowCellTemplate1;
                else
                    return RowCellTemplate2;
            }
            return base.SelectTemplate(item, container);
        }

Check this link for details:How to: Select Templates Based on Custom Logic

Here is a sample also available that deals with Unbound data.. try to use Image in unbound field .. How to: Display Unbound Data

Try this .. Hope it help you to implement.. You should look for DXGRid Demo

Upvotes: 1

Related Questions