欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

c#數(shù)據(jù)綁定之將datatabel的data添加listView

 更新時(shí)間:2014年04月10日 14:15:22   作者:  
這篇文章主要介紹了c#將DataTabel的data添加ListView的示例,實(shí)現(xiàn)功能是通過(guò)響應(yīng)UI Textbox 的值向ListView 綁定新添加的紀(jì)錄。 ,需要的朋友可以參考下



功能:通過(guò)響應(yīng)UI Textbox 的值向ListView 綁定新添加的紀(jì)錄。

UI XAML 代碼

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

<Grid Margin="5">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition  Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <TextBlock  Grid.Row="0" Grid.Column="0" Text="商品名稱" HorizontalAlignment="Right" VerticalAlignment="Center" />
            <TextBox Grid.Row="0" Grid.Column="1" Margin="2" VerticalAlignment="Center" Text="{Binding Path=ComName}" Name="tbkName"/>
            <TextBlock  Grid.Row="1" Grid.Column="0" Text="商品進(jìn)貨單價(jià)" HorizontalAlignment="Right" VerticalAlignment="Center" />
            <TextBox Grid.Row="1" Grid.Column="1" Margin="2" VerticalAlignment="Center" Text="{Binding Path=ComInPrice}" Name="tbkInPrice"/>
            <TextBlock  Grid.Row="2" Grid.Column="0" Text="商品零售價(jià)格" HorizontalAlignment="Right" VerticalAlignment="Center" />
            <TextBox Grid.Row="2" Grid.Column="1" Margin="2" VerticalAlignment="Center" Text="{Binding Path=ComOutPrice}" Name="tbkOutPrice"/>
            <TextBlock  Grid.Row="3" Grid.Column="0" Text="進(jìn)貨數(shù)量" HorizontalAlignment="Right" VerticalAlignment="Center" />
            <TextBox Grid.Row="3" Grid.Column="1" Margin="2" VerticalAlignment="Center" Text="{Binding Path=ComOutPrice}" Name="tbkComCount"/>

            <Button Grid.Row="4" Grid.Column="1" Content="添加新紀(jì)錄" Margin="2" Padding="2" Name="btnAdd" Click="btnAdd_Click" />

            <TextBlock Grid.Row="5" Grid.ColumnSpan="2"  HorizontalAlignment="Stretch"  VerticalAlignment="Center"  Background="Black" />

            <ListView Name="lstDisplay" ItemsSource="{Binding}" Grid.Row="6" Grid.ColumnSpan="2">
                <ListView.View>
                    <GridView>
                        <GridView.Columns>
                            <GridViewColumn  Header="AutoID" DisplayMemberBinding="{Binding AutoID}"/>
                            <GridViewColumn Header="商品名稱" DisplayMemberBinding="{Binding ComName}"/>
                            <GridViewColumn Header="進(jìn)貨價(jià)格" DisplayMemberBinding="{Binding Path=ComInPrice,StringFormat={}{0:c}}"/>
                            <GridViewColumn Header="零售價(jià)格" DisplayMemberBinding="{Binding Path=ComOutPrice,StringFormat={}{0:c}}"/>
                            <GridViewColumn Header="進(jìn)貨數(shù)量" DisplayMemberBinding="{Binding ComCount}"/>
                        </GridView.Columns>
                    </GridView>
                </ListView.View>
            </ListView>
        </Grid>

c#后代碼

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

DataTable Commodity = newTable();

        public MainWindow()
        {
            InitializeComponent();
            //DataTable Commodity = newTable();

        }

      

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {

            addNewMember(Commodity);
            lstDisplay.DataContext = Commodity;

        }

        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            Button b = sender as Button;
            Int32 AutoID = Convert.ToInt32(b.CommandParameter);
            delMember(Commodity, AutoID);
            lstDisplay.DataContext = Commodity;
            lstDisplay.Items.Refresh();

        }

        private DataTable delMember(DataTable Table,Int32 laction)
        {
            //Deleting  a existed row in datatable Commodity;
            DataRow delRow = Table.Rows.Find(laction);
            Table.Rows.Remove(delRow);
            return Table;
        }

        private  DataTable addNewMember(DataTable Table)
        {
           

            //inserting a new row in datatable Commodity;

            DataRow newRow = Table.NewRow();
            newRow["ComName"] = tbkName.Text;
            newRow["ComInPrice"] = tbkInPrice.Text;
            newRow["ComOutPrice"] = tbkOutPrice.Text;
            newRow["ComCount"] = tbkComCount.Text;
            Table.Rows.Add(newRow);
            return Table;
        }

 

        private static DataTable newTable()
        {
            //Create a new table named Commodity
            DataTable commodity = new DataTable("Commodity");


            //instert new columns
            DataColumn auto = new DataColumn("AutoID", typeof(Int32));
            //setting the column auto increment
            auto.AutoIncrement = true;
            commodity.Columns.Add(auto);
            commodity.Columns.Add("ComName", typeof(string));
            commodity.Columns.Add("ComInPrice", typeof(double));
            commodity.Columns.Add("ComOutPrice", typeof(double));
            commodity.Columns.Add("ComCount", typeof(System.Int32));
            commodity.PrimaryKey = new DataColumn[] { commodity.Columns[0] };
            return commodity;
        }

相關(guān)文章

  • 利用多線程句柄設(shè)置鼠標(biāo)忙碌狀態(tài)的實(shí)現(xiàn)方法

    利用多線程句柄設(shè)置鼠標(biāo)忙碌狀態(tài)的實(shí)現(xiàn)方法

    怎樣利用多線程句柄設(shè)置鼠標(biāo)忙碌狀態(tài)呢?下面小編就為大家介紹一下具體的實(shí)現(xiàn)方法吧!需要的朋友可以過(guò)來(lái)參考下
    2013-08-08
  • C#使用GZipStream實(shí)現(xiàn)文件的壓縮與解壓

    C#使用GZipStream實(shí)現(xiàn)文件的壓縮與解壓

    這篇文章主要為大家詳細(xì)介紹了C#使用GZipStream實(shí)現(xiàn)文件的壓縮與解壓,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-10-10
  • Winform控件優(yōu)化Paint事件實(shí)現(xiàn)圓角組件及提取繪制圓角的方法

    Winform控件優(yōu)化Paint事件實(shí)現(xiàn)圓角組件及提取繪制圓角的方法

    這篇文章主要介紹了Winform控件優(yōu)化Paint事件實(shí)現(xiàn)圓角組件及提取繪制圓角的方法,Windows?11下所有控件已經(jīng)默認(rèn)采用圓角,其效果更好、相對(duì)有著更好的優(yōu)化,只是這是默認(rèn)的行為,無(wú)法進(jìn)一步自定義,更多詳情需要的小伙伴可以參考下面文章內(nèi)容
    2022-08-08
  • C# System.TypeInitializationException 異常處理方案

    C# System.TypeInitializationException 異常處理方案

    這篇文章主要介紹了C# System.TypeInitializationException 異常處理方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-02-02
  • C# 9.0 特性全面總結(jié)

    C# 9.0 特性全面總結(jié)

    這篇文章主要介紹了C# 9.0 特性的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下
    2021-02-02
  • C#中struct和class的區(qū)別詳解

    C#中struct和class的區(qū)別詳解

    這篇文章主要介紹了C#中struct和class的區(qū)別,對(duì)C#初學(xué)者來(lái)說(shuō)是需要牢固掌握的,需要的朋友可以參考下
    2014-08-08
  • C#委托用法詳解

    C#委托用法詳解

    本文詳細(xì)講解了C#中委托的用法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-02-02
  • 關(guān)于C#連接SQL Server時(shí)提示用戶登錄失敗的解決方法

    關(guān)于C#連接SQL Server時(shí)提示用戶登錄失敗的解決方法

    在用C#開(kāi)發(fā)windows端程序并連接SQL Server時(shí)有可能會(huì)遇到數(shù)據(jù)庫(kù)登錄失敗的問(wèn)題,下面小編給大家?guī)?lái)了C#連接SQL Server時(shí)提示用戶登錄失敗的解決方法,感興趣的朋友一起看看吧
    2021-11-11
  • WPF利用RPC調(diào)用其他進(jìn)程的方法詳解

    WPF利用RPC調(diào)用其他進(jìn)程的方法詳解

    這篇文章主要給大家介紹了關(guān)于WPF利用RPC調(diào)用其他進(jìn)程的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2018-05-05
  • C#開(kāi)發(fā)Winform實(shí)現(xiàn)學(xué)生管理系統(tǒng)

    C#開(kāi)發(fā)Winform實(shí)現(xiàn)學(xué)生管理系統(tǒng)

    這篇文章介紹了C#開(kāi)發(fā)Winform實(shí)現(xiàn)學(xué)生管理系統(tǒng)的項(xiàng)目案例,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-05-05

最新評(píng)論