标题:wpf datagrid 跟数据库绑定 只显示一行,也就是数据库里的第一行内容
取消只看楼主
foxxo51x
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-1-16
 问题点数:0 回复次数:2 
wpf datagrid 跟数据库绑定 只显示一行,也就是数据库里的第一行内容
代码        
 dataGrid1.CanUserAddRows = true;
           dt = new DataSet();
           OleDbDataAdapter objAdapter8 = new OleDbDataAdapter("select * from UserName", ConnectionAccess);
           objAdapter8.Fill(dt, "UserName");
           this.dataGrid1.ItemsSource = dt.Tables;
           ConnectionAccess.Close();
搜索更多相关主题的帖子: 数据库 
2014-01-16 15:50
foxxo51x
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-1-16
得分:0 
显示在 datagrid只显示了数据库里第一行数据,其它行都没有显示,这是为什么?
开始没有将清楚
2014-01-16 15:56
foxxo51x
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-1-16
得分:0 
这是前台程序
<DataGrid  Height="745" Width="956" HorizontalAlignment="Left" Margin="279,24,0,0" Name="dataGrid1" VerticalAlignment="Top"  AutoGenerateColumns="False"  IsReadOnly="True" FontFamily="Adobe Song Std" FontSize="15" FontWeight="Black"  IsManipulationEnabled="False" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="False" CanUserResizeRows="False" SelectionMode="Single" Canvas.Left="-183" Canvas.Top="-92">
            <!--设置列关键字类型-->
            <DataGrid.ColumnHeaderStyle>
                <Style TargetType="DataGridColumnHeader">
                    <Setter Property="HorizontalContentAlignment" Value="Center">
                    </Setter>
                </Style>
            </DataGrid.ColumnHeaderStyle>
            <!--设置行头类型-->
            <DataGrid.RowHeaderStyle>
                <Style TargetType="DataGridRowHeader">
                    <Setter Property="Content" Value="*"/>
                    <Setter Property="Width" Value="20"/>
                    <Setter Property="HorizontalContentAlignment" Value="Center"/>
                    <Setter Property="Background">
                        <Setter.Value>
                            <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                                <GradientStop Color="White" Offset="0"/>
                                <GradientStop Color="#FF9D9D9D" Offset="0.5"/>
                                <GradientStop Color="White" Offset="1"/>
                            </LinearGradientBrush>
                        </Setter.Value>
                    </Setter>
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="ToolTip" Value="Select this Row"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.RowHeaderStyle>
            <!--设置行类型-->
            <DataGrid.RowStyle>
                <Style TargetType="DataGridRow">
                    <Setter Property="Background" Value="LightBlue" />
                    <Setter Property="HorizontalContentAlignment" Value="Center"/>
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="LightGray"/>
                            <Setter Property="Foreground" Value="White"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.RowStyle>
            <!--设置列显示内容类型-->
            <DataGrid.Columns>
                <DataGridTextColumn Header="序号" Width="50" Binding="{Binding XH,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                <DataGridTemplateColumn Header="照    片" Width="150"  IsReadOnly="True" >
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image Height="80"  Source="{Binding ZP,Mode=OneWay}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                        <!--设置-->
                    <DataGridColumn.HeaderStyle>
                        <Style TargetType="DataGridColumnHeader">
                            <Setter Property="Background">
                                <Setter.Value>
                                    <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                        <GradientStop Color="White" Offset="0"/>
                                        <GradientStop Color="#FF9D9D9D" Offset="0.5"/>
                                        <GradientStop Color="White" Offset="1"/>
                                    </LinearGradientBrush>
                                </Setter.Value>
                            </Setter>
                            <Setter Property="HorizontalContentAlignment" Value="Center"/>
                        </Style>
                    </DataGridColumn.HeaderStyle>
                </DataGridTemplateColumn>
                <DataGridTextColumn Header="姓    名" Width="150" Binding="{Binding XM,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                </DataGridTextColumn>
                <DataGridTextColumn Header="门卡编号" Width="150" Binding="{Binding MKBH, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                <DataGridTextColumn Header="工    号" Width="150" Binding="{Binding GH, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                <DataGridTextColumn Header="部门名称" Width="150" Binding="{Binding BMMC, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                <DataGridTextColumn Header="考勤管理" Width="70" Binding="{Binding KQGL, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                <DataGridTextColumn Header="门禁管理" Width="70" Binding="{Binding MJGL,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
            </DataGrid.Columns>
        </DataGrid>
2014-01-16 16:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-426572-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.104012 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved