小编Gop*_*opi的帖子

DataGridComboBoxColumn用于不同行的不同ItemsSource

这里提出类似于我的问题的问题,但我没有在那里找到解决方案.

我的问题:如何将不同数据(比如Lists)绑定到不同行中每个ComboBox的"DataGridComboBoxColumn".这是我试过的代码

XAML:

<Grid>
    <DataGrid x:Name="dg_TimeTable" AutoGenerateColumns="False" Margin="0,0,0,97" ColumnWidth="*">
        <DataGrid.Columns>
            <DataGridTextColumn IsReadOnly="True" Binding="{Binding CLASS}" Header="CLASS" />

            <DataGridComboBoxColumn Header="PERIOD" x:Name="gPeriods" SelectedValueBinding="{Binding PERIOD, Mode=TwoWay}" DisplayMemberPath="{Binding PERIOD}" />

            <DataGridComboBoxColumn Header="TEACHERS" x:Name="gTeachers" SelectedValueBinding="{Binding TEACHER, Mode=TwoWay}" DisplayMemberPath="{Binding TEACHER}" />

            <DataGridComboBoxColumn Header="SUBJECTS" x:Name="gSubjects" SelectedValueBinding="{Binding SUBJECT, Mode=TwoWay}" DisplayMemberPath="{Binding SUBJECT}"/>
        </DataGrid.Columns>
    </DataGrid>
</Grid>
Run Code Online (Sandbox Code Playgroud)

的.cs

using System.Collections.ObjectModel; // For ObservableCollection

public partial class MainWindow : Window
{
    ObservableCollection<string> listTeachersSix = null;
    ObservableCollection<string> listTeachersSeven = null;
    ObservableCollection<string> listTeachersEight = null;
    ObservableCollection<string> listTeachersNine = null;
    ObservableCollection<string> listTeachersTen = null; …
Run Code Online (Sandbox Code Playgroud)

c# wpf wpfdatagrid datagridcomboboxcolumn

7
推荐指数
1
解决办法
2035
查看次数

在ListView中更改列标题的字体样式和颜色

我搜索了更改我们使用的ListView的标题颜色:

private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
    e.Graphics.FillRectangle(Brushes.Pink, e.Bounds);
    e.DrawText();
}
Run Code Online (Sandbox Code Playgroud)

我们使用相同的事件来更改ListView的标题样式:

private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
    using (StringFormat sf = new StringFormat())
    {
        sf.Alignment = StringAlignment.Center;
        e.DrawBackground();

        using (Font headerFont =
            new Font("Microsoft Sans Serif", 9, FontStyle.Bold)) //Font size!!!!
        {
            e.Graphics.DrawString(e.Header.Text, headerFont, 
                Brushes.Black, e.Bounds, sf);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我的问题是我想要改变标题颜色和标题样式.所以我这样写:

private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
    e.Graphics.FillRectangle(Brushes.Pink, e.Bounds);
    e.DrawText();

    using (StringFormat sf = new StringFormat())
    {
        sf.Alignment = StringAlignment.Center;
        e.DrawBackground();

        using (Font headerFont =
            new Font("Microsoft …
Run Code Online (Sandbox Code Playgroud)

.net c# winforms

3
推荐指数
1
解决办法
2万
查看次数

在 WPF 中打印 DataGrid 中的所有数据

我正在研究 WPF 应用程序。我在 DataGrid 中有数据,我必须打印其中存在的所有数据。我试过这样...

publicMainWindow()
    {
       InitializeComponent();

       DataTabledt = newDataTable();
       dt.Columns.Add("S.No");
       dt.Columns.Add("Name");
       dt.Columns.Add("Father's Name");
       dt.Columns.Add("D-O-B");
       dt.Columns.Add("Qualification");
       dt.Columns.Add("Gender");
       dt.Columns.Add("SSC %");
       dt.Columns.Add("+2 %");
       dt.Columns.Add("Graduation %");
       dt.Columns.Add("Work Experience");
       dt.Columns.Add("Company");

       object[] rowValues = {"01","Gopi","Ravi","31","Degree","M", "88","85", "80","2 Years","Blah Blah"};

       dt.Rows.Add(rowValues);
       dt.AcceptChanges();
       myGrid.DataContext = dt.DefaultView;
    }

       privatevoidPrint_Click(object sender, RoutedEventArgs e)
    {
       PrintDialogprintDlg = newPrintDialog();
       if ((bool)printDlg.ShowDialog().GetValueOrDefault())
        {
       Sizepagesize = newSize(printDlg.PrintableAreaWidth,printDlg.PrintableAreaHeight);
       myGrid.Measure(pagesize);
       myGrid.Arrange(newRect(5, 5, pagesize.Width, pagesize.Height));
            printDlg.PrintVisual(myGrid, "Personal Information");

        }
    }
Run Code Online (Sandbox Code Playgroud)

当我点击打印按钮时,它只打印我们可以看到的数据,如下所示 在此处输入图片说明

但就我而言,它不是打印工作经验和公司专栏。如何打印所有字段。请帮帮我

编辑:我认为使用 FlowDocument,但假设我有 50 行我不能使用 FlowDocument。在这种情况下我如何打印。

.net c# printing wpf datagrid

2
推荐指数
1
解决办法
8232
查看次数