0
votes

I have created a WPF datagrid and the columns are static (costume columns). Data grid rows are binding as per the data from data table rows. I want to set values to the WPF DataGrid cells dynamically from another ArrayList.

I'm not finding the cell index of rows, like dataGrid.Rows[i].Cells[j] = ArrayList[k].

Can anyone please help me? I'm new to WPF.

Thanks in advance.

1

1 Answers

0
votes

if you have static ArrayList, your code can be like this:

<Grid Name="MyArray" Margin=”10”>
    <Grid.DataContext>
        <x:Array Type=”sys:String”>
        <sys:String>Red</sys:String>
        <sys:String>Yellow</sys:String>
        <sys:String>Lime</sys:String>
        <sys:String>Cyan</sys:String>
        <sys:String>Blue</sys:String>
        <sys:String>Magenta</sys:String>
        </x:Array>
    </Grid.DataContext>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width=”*”/>
    </Grid.ColumnDefinitions>
    <!--here your dataGrid-->
    then you should write like this
    <Label Content="{Binding ElementName=MyArray, Path=DataContext[0]}" />
    and so on...
    </Grid>

correct me if I understand you wrong.