Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
XMAIL CODE:
HTML
<window x:class="WpfApplication5.MainWindow" xmlns:x="#unknown">
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="550" Width="525">
    <grid height="500" uselayoutrounding="False">
        <Label Content="EID" Height="28" HorizontalAlignment="Left" Margin="136,90,0,0" Name="label1" VerticalAlignment="Top" Width="78" />
        <textbox height="23" horizontalalignment="Left" margin="220,90,0,0" name="textBox1" verticalalignment="Top" width="120" />
        <Label Content="Name" Height="28" HorizontalAlignment="Left" Margin="136,124,0,0" Name="label2" VerticalAlignment="Top" Width="78" />
        <textbox height="23" horizontalalignment="Left" margin="220,124,0,0" name="textBox2" verticalalignment="Top" width="209" />
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="220,153,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
        <datagrid autogeneratecolumns="False" height="200" margin="14,200,0,0" name="dataGrid1" verticalalignment="Top" width="477">
            <datagrid.columns>
                <datagridtemplatecolumn width="100">
                    <datagridtemplatecolumn.headertemplate>
                        <datatemplate>
                            <checkbox name="hcb" checked="hcb_Checked" horizontalalignment="Center"></checkbox>
                        </datatemplate>
                    </datagridtemplatecolumn.headertemplate>
                    <datagridtemplatecolumn.celltemplate>
                        <datatemplate>
                            <checkbox name="cb" horizontalalignment="Center"></checkbox>
                        </datatemplate>
                    </datagridtemplatecolumn.celltemplate>
                </datagridtemplatecolumn>
                <datagridtextcolumn header="EID" binding="{Binding ID}" width="200"></datagridtextcolumn>
                <datagridtextcolumn header="NAME" binding="{Binding NAME}" width="250"></datagridtextcolumn>
            </datagrid.columns>
        </datagrid>
        <grid.background>
            <radialgradientbrush>
                <gradientstop color="Chartreuse" offset="0" />
                <gradientstop color="White" offset="1" />
            </radialgradientbrush>
        </grid.background>
    </grid>
</window>
C# CODE USING WPF
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication5
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        #region
        ServiceReference1.ServiceClient obj = new ServiceReference1.ServiceClient();
        #endregion
        public MainWindow()
        {
            InitializeComponent();
            fill();
        }
        void fill()
        {
            dataGrid1.ItemsSource = obj.view();
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            ServiceReference1.ValList x = new ServiceReference1.ValList();
            x.ID = Convert.ToInt32(textBox1.Text);
            x.NAME = textBox2.Text;
            obj.insert(x);
            MessageBox.Show("One record saved.");
            fill();
        }

       

        private void hcb_Checked(object sender, RoutedEventArgs e)
        {

            MessageBox.Show("hi");
          
        }

       
    }
}
Posted
Updated 29-Sep-12 0:20am
v2

1 solution

xaml code:
HTML
<Window x:Class="WpfApplication5.Window3"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window3" Height="300" Width="300" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
<Grid>
    <DataGrid AutoGenerateColumns="False" Height="200" HorizontalAlignment="Left" Margin="33,20,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="200">
        <DataGrid.Columns>
            <DataGridTemplateColumn>
                <DataGridTemplateColumn.HeaderTemplate>
                    <DataTemplate>
                        <CheckBox Name="hcb" Checked="hcb_Checked" Unchecked="hcb_Unchecked"></CheckBox>
                    </DataTemplate>
                </DataGridTemplateColumn.HeaderTemplate>
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <CheckBox Name="cb" Width="50"  IsChecked="{Binding  Path = c , Mode = TwoWay}"></CheckBox>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>

            <DataGridTextColumn Binding="{Binding s}" Header="NAME" Width="150"></DataGridTextColumn>
        </DataGrid.Columns>
    </DataGrid>
</Grid>
</Window>

C# code:
C#
using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Shapes;
    
    namespace WpfApplication5
    {
    /// <summary>
    /// Interaction logic for Window3.xaml
    /// </summary>
    public partial class Window3 : Window
    {
        public Window3()
        {
            InitializeComponent();
        }
        #region
        ServiceReference1.ServiceClient o = new ServiceReference1.ServiceClient();
    #endregion
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            List<xx> obj = new List<xx>();
            for (int i = 0; i < o.view().ToList().Count;i++ )
            {
                xx y = new xx();
                y.s = o.view().ToList()[i].NAME;
                y.c = false;
                obj.Add(y);
            }
    
            dataGrid1.ItemsSource = obj;
        }
        public class xx
        {
            public string s
            {
                get;
                set;
            }
            public bool c
            {
                get;
                set;
            }
        }
    
        private void hcb_Checked(object sender, RoutedEventArgs e)
        {
            List<xx> obj = new List<xx>();
            for (int i = 0; i < o.view().ToList().Count; i++)
            {
                xx y = new xx();
                y.s = o.view().ToList()[i].NAME;
                y.c = true;
                obj.Add(y);
            }
            dataGrid1.ItemsSource = obj;
        }
    
        private void hcb_Unchecked(object sender, RoutedEventArgs e)
        {
            List<xx> obj = new List<xx>();
            for (int i = 0; i < o.view().ToList().Count; i++)
            {
                xx y = new xx();
                y.s = o.view().ToList()[i].NAME;
                y.c = false;
                obj.Add(y);
            }
            dataGrid1.ItemsSource = obj;
        }
    }
    }
 
Share this answer
 
v4
Comments
musthe 24-Apr-20 5:52am    
Please, can you use MVVM pattern ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900