最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

c#數(shù)據(jù)綁定之?dāng)?shù)據(jù)轉(zhuǎn)化為信息的示例

 更新時(shí)間:2014年04月10日 14:29:12   作者:  
這篇文章主要介紹了c#數(shù)據(jù)綁定中的數(shù)據(jù)轉(zhuǎn)化為信息的示例,需要的朋友可以參考下

目標(biāo)界面:

XAML代碼:

復(fù)制代碼 代碼如下:

<Grid Margin="2">
            <Grid.RowDefinitions>
                <RowDefinition  Height="Auto"/>
                <RowDefinition  Height="Auto"/>
                <RowDefinition  Height="Auto"/>
                <RowDefinition />
            </Grid.RowDefinitions>
            <GroupBox Header="Customer" Grid.Row="0" Padding="5">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Row="0" Grid.Column="0" Text="CustomerID" Margin="2" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                    <TextBox Grid.Row="0" Grid.Column="1" Margin="2" Name="tbxCustomerID" Text="{Binding Path=CID}"/>
                    <TextBlock Grid.Row="1" Grid.Column="0" Text="CustomerName" Margin="2" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                    <TextBox Grid.Row="1" Grid.Column="1" Margin="2" Name="tbxCustomerName" Text="{Binding Path=Name}"/>
                    <Button Grid.Row="2" Grid.Column="1" Content="Add New Customer" Margin="2" Name="btnAddCustomer" Padding="2" Click="btnAddCustomer_Click" />
                </Grid>
            </GroupBox>
            <GroupBox Header="Order" Grid.Row="1" Padding="5">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Row="0" Grid.Column="0" Text="OrderID" Margin="2" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                    <TextBox Grid.Row="0" Grid.Column="1" Margin="2" Name="tbxOrderID" Text="{Binding Path=OID}"/>
                    <TextBlock Grid.Row="1" Grid.Column="0" Text="OrderName" Margin="2" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                    <TextBox Grid.Row="1" Grid.Column="1" Margin="2" Name="tbxOrderName" Text="{Binding Path=Customer}"/>
                    <TextBlock Grid.Row="2" Grid.Column="0" Text="Subtotal" Margin="2" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                    <TextBox Grid.Row="2" Grid.Column="1" Margin="2" Name="tbxSubtotal" Text="{Binding Path=Subtotal}"/>
                    <TextBlock Grid.Row="3" Grid.Column="0" Text="TaxRate" Margin="2" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                    <TextBox Grid.Row="3" Grid.Column="1" Margin="2" Name="tbxTaxRate" Text="{Binding Path=TaxRate}"/>
                    <Button Grid.Row="4" Grid.Column="1" Content="Add New Order" Margin="2" Name="btnAddOrder" Padding="2" Click="btnAddOrder_Click" />
                </Grid>
            </GroupBox>
            <ListView Name="lstDisplayCustomer" ItemsSource="{Binding}" Grid.Row="2"  Margin="2" MinHeight="150">
                <ListView.View>
                    <GridView>
                        <GridView.Columns>
                            <GridViewColumn  Header="CustomerID" DisplayMemberBinding="{Binding CID}"/>
                            <GridViewColumn Header="CustomerName" DisplayMemberBinding="{Binding Name}"/>
                            <GridViewColumn Header="Total" DisplayMemberBinding="{Binding OrderTotals}" />
                        </GridView.Columns>
                    </GridView>
                </ListView.View>
            </ListView>
            <ListView Name="lstDisplayOrder" ItemsSource="{Binding}" Grid.Row="3"  Margin="2" MinHeight="150">
                <ListView.View>
                    <GridView>
                        <GridView.Columns>
                            <GridViewColumn  Header="OrderID" DisplayMemberBinding="{Binding OID}"/>
                            <GridViewColumn Header="Customer" DisplayMemberBinding="{Binding Customer}"/>
                            <GridViewColumn Header="Subtotal" DisplayMemberBinding="{Binding Subtotal}"/>
                            <GridViewColumn Header="TaxRate"  DisplayMemberBinding="{Binding TaxRate}" />
                            <GridViewColumn Header="Total"    DisplayMemberBinding="{Binding Total}"/>
                        </GridView.Columns>
                    </GridView>
                </ListView.View>
            </ListView>
        </Grid>

C# 代碼:

復(fù)制代碼 代碼如下:

DataSet business = NewData();

        public MainWindow()
        {
            InitializeComponent();

        }

        private static DataSet NewData()
        {
            //-----build the parent table and add some data
            DataTable customer = new DataTable("Customer");
            customer.Columns.Add("CID", typeof(Int32));
            customer.Columns.Add("Name", typeof(string));
            //-------build the child table and add some data.
            DataTable orders = new DataTable("Order");
            orders.Columns.Add("OID", typeof(int));
            orders.Columns.Add("Customer", typeof(Int32));
            orders.Columns.Add("Subtotal", typeof(decimal));
            orders.Columns.Add("TaxRate", typeof(decimal));
            orders.Columns.Add("Total",typeof(decimal),"Subtotal*(1+TaxRate)");

            //-----Link the table within a Dataset.
            DataSet business = new DataSet();
            business.Tables.Add(customer);
            business.Tables.Add(orders);
            business.Relations.Add(customer.Columns["CID"],orders.Columns["Customer"]);
            customer.Columns.Add("OrderTotals" ,typeof(decimal),"Sum(Child.Total)");
            return business;
        }

        private void btnAddCustomer_Click(object sender, RoutedEventArgs e)
        {
           //Vist datatable customer.
            DataTable customer=business.Tables["Customer"];
            NewMember(customer);
            lstDisplayCustomer.DataContext = customer;
        }

        private DataTable NewMember(DataTable table)
        {
            DataRow newRow = table.NewRow();
            newRow["CID"] = tbxCustomerID.Text;
            newRow["Name"] = tbxCustomerName.Text;
            table.Rows.Add(newRow);
            return table;
        }

        private DataTable NewMemberOrder(DataTable table)
        {
            DataRow newRow = table.NewRow();
            newRow["OID"] = tbxOrderID.Text;
            newRow["Customer"] = tbxOrderName.Text;
            newRow["Subtotal"] = tbxSubtotal.Text;
            newRow["TaxRate"] = tbxTaxRate.Text;
            table.Rows.Add(newRow);
            return table;
        }

        private void btnAddOrder_Click(object sender, RoutedEventArgs e)
        {
            //Vist datatable order.
            DataTable order = business.Tables["Order"];
            NewMemberOrder(order);
            lstDisplayOrder.DataContext = order;
        }

相關(guān)文章

  • 深入c# GDI+簡單繪圖的具體操作步驟(二)

    深入c# GDI+簡單繪圖的具體操作步驟(二)

    本篇文章是對(duì)GDI+簡單繪圖的繪圖知識(shí)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • 基于C#實(shí)現(xiàn)一個(gè)簡單的FTP操作工具

    基于C#實(shí)現(xiàn)一個(gè)簡單的FTP操作工具

    這篇文章主要為大家詳細(xì)介紹了如何利用C#實(shí)現(xiàn)一個(gè)簡單的FTP操作工具,可以實(shí)現(xiàn)FTP上傳、下載、重命名、刷新、刪除功能,感興趣的可以了解一下
    2022-08-08
  • C#中的預(yù)定義類型與引用類型

    C#中的預(yù)定義類型與引用類型

    這篇文章介紹了C#中的預(yù)定義類型與引用類型,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-05-05
  • C# 泛型的簡單理解(安全、集合、方法、約束、繼承)分享

    C# 泛型的簡單理解(安全、集合、方法、約束、繼承)分享

    這篇文章介紹了C# 泛型的簡單理解(安全、集合、方法、約束、繼承),有需要的朋友可以參考一下
    2013-10-10
  • 基于WPF實(shí)現(xiàn)面包屑效果的示例代碼

    基于WPF實(shí)現(xiàn)面包屑效果的示例代碼

    這篇文章主要為大家詳細(xì)介紹了如何基于WPF實(shí)現(xiàn)面包屑效果,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)或工作有一定幫助,感興趣的小伙伴可以了解一下
    2023-04-04
  • c#如何利用定時(shí)器自動(dòng)備份數(shù)據(jù)庫詳解

    c#如何利用定時(shí)器自動(dòng)備份數(shù)據(jù)庫詳解

    在開發(fā)過程當(dāng)中,你一定遇到文件損壞活或丟失的煩惱,而每天備份又很麻煩,你只要設(shè)置每天備份的時(shí)間,并將程序加入啟動(dòng)項(xiàng)中,就可以自動(dòng)完成備份,這篇文章主要給大家介紹了關(guān)于c#如何利用定時(shí)器自動(dòng)備份數(shù)據(jù)庫的相關(guān)資料,需要的朋友可以參考下
    2021-10-10
  • C# DatagridView常用操作匯總

    C# DatagridView常用操作匯總

    這篇文章主要介紹了C# DatagridView常用操作匯總,羅列了一些常用的用法與技巧,需要的朋友可以參考下
    2014-07-07
  • 淺談C#多線程簡單例子講解

    淺談C#多線程簡單例子講解

    本篇文章主要介紹了C#多線程簡單例子,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2016-12-12
  • C#生成防偽碼的思路及源碼分享

    C#生成防偽碼的思路及源碼分享

    生成防偽碼其實(shí)挺簡單,但是如果要考慮效率和不重復(fù)的話,就需要稍微動(dòng)動(dòng)腦子了,下面我來說說我的思路及源碼
    2014-06-06
  • .NET/C# 使用Stopwatch測(cè)量運(yùn)行時(shí)間

    .NET/C# 使用Stopwatch測(cè)量運(yùn)行時(shí)間

    這篇文章主要介紹了.NET/C# 使用Stopwatch測(cè)量運(yùn)行時(shí)間,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-01-01

最新評(píng)論

楚雄市| 海南省| 白银市| 萍乡市| 乐至县| 郎溪县| 石楼县| 合作市| 景洪市| 民县| 定州市| 军事| 塔城市| 盱眙县| 藁城市| 罗山县| 蓬安县| 岚皋县| 德庆县| 都江堰市| 博兴县| 改则县| 邳州市| 广南县| 巢湖市| 南澳县| 亚东县| 恭城| 孟村| 固始县| 石狮市| 鲁山县| 哈尔滨市| 大冶市| 正蓝旗| 洛隆县| 潞西市| 方城县| 溧水县| 博乐市| 察隅县|