Получить данные из сетки данных C # wpf - PullRequest
0 голосов
/ 14 февраля 2019

как получить данные из таблицы данных?

код xobobox xml:

я подключаю комбо к таблице MahName

combobox1.ItemsSource = database.Mahs.ToList();

combobox1.DisplayMemberPath = "MahName";

это кодовая сетка данных

    <DataGrid.Columns>
        <DataGridTextColumn Header="کد محصول" Binding="{Binding MahID}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>
        <DataGridTextColumn Header="نام محصول" Binding="{Binding MahName}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>
        <DataGridTextColumn Header=" قیمت فروش" Binding="{Binding MahFe}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header="نام ماده اول" Binding="{Binding Mah1}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header="نام ماده دوم" Binding="{Binding Mah2}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header="نام ماده سوم" Binding="{Binding Mah3}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header="نام ماده چهارم" Binding="{Binding Mah4}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>


        <DataGridTextColumn Header="نام ماده پنجم" Binding="{Binding Mah5}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header="نام ماده ششم" Binding="{Binding Mah6}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header="نام ماده هفتم" Binding="{Binding Mah7}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header="نام ماده هشتم" Binding="{Binding Mah8}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header="نام ماده نهم" Binding="{Binding Mah9}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header="نام ماده دهم" Binding="{Binding Mah10}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header="وزن ماده اول" Binding="{Binding Mahg1}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header="وزن ماده دوم" Binding="{Binding Mahg2}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header="وزن ماده سوم" Binding="{Binding Mahg3}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header="وزن ماده چهارم" Binding="{Binding Mahg4}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>


        <DataGridTextColumn Header="وزن ماده پنجم" Binding="{Binding Mahg5}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header="وزن ماده ششم" Binding="{Binding Mahg6}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header="وزن ماده هفتم" Binding="{Binding Mahg7}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header="وزن ماده هشتم" Binding="{Binding Mahg8}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header="وزن ماده نهم" Binding="{Binding Mahg9}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header="وزن ماده دهم" Binding="{Binding Mahg10}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />



       <Setter Property="HorizontalContentAlignment" Value="Center" />
                    </Style>
                </DataGridTextColumn.HeaderStyle>
            </DataGridTextColumn>






<DataGridTextColumn Header=" قیمت ماده اول" Binding="{Binding Mahf1}">
                    <DataGridTextColumn.HeaderStyle>
                        <Style TargetType="{x:Type DataGridColumnHeader}">
                            <Setter Property="FontFamily" Value="B Yekan" />
                            <Setter Property="FontSize" Value="12" />

                            <Setter Property="HorizontalContentAlignment" Value="Center" />
                        </Style>
                    </DataGridTextColumn.HeaderStyle>
                </DataGridTextColumn>
        <DataGridTextColumn Header=" قیمت ماده دوم" Binding="{Binding Mahf2}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header=" قیمت ماده سوم" Binding="{Binding Mahf3}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header=" قیمت ماده چهارم" Binding="{Binding Mahf4}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header=" قیمت ماده پنجم" Binding="{Binding Mahf5}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header=" قیمت ماده ششم" Binding="{Binding Mahf6}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header=" قیمت ماده هفتم" Binding="{Binding Mahf7}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>


        <DataGridTextColumn Header=" قیمت ماده هشتم" Binding="{Binding Mahf8}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

        <DataGridTextColumn Header=" قیمت ماده نهم" Binding="{Binding Mahf9}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>





        <DataGridTextColumn Header="سود" Binding="{Binding Mahd}">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontFamily" Value="B Yekan" />
                    <Setter Property="FontSize" Value="12" />

                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>

    </DataGrid.Columns>

</DataGrid>

я хочу, когда combobox.text = "MahName" в сетке данных, затем "Mahg1" в сетке данных / 1000, затем * "Mahf1" в сетке данных ...

"Mahg10" в сетке данных / 1000, затем * "Mah10" в сетке данных

Mahf - это цена, а Mahg - это вес

что мне делать?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...