Click here to Skip to main content
Sign Up to vote bad
good
See more: WPF
XMAIL CODE:
<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
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 28 Sep '12 - 23:09
Edited 29 Sep '12 - 0:20
JF201551.4K


1 solution

xaml code:
    <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:
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;
        }
    }
    }
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 545
1 Maciej Los 270
2 Slacker007 240
3 OriginalGriff 235
4 Aarti Meswania 185
0 Sergey Alexandrovich Kryukov 8,953
1 OriginalGriff 7,134
2 CPallini 3,758
3 Rohan Leuva 3,066
4 Maciej Los 2,528


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 1 Oct 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid