Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:09pm
Edited 29-Sep-12 0:20am
JF201553.1K
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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  
v4

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

  Print Answers RSS
0 OriginalGriff 328
1 Sergey Alexandrovich Kryukov 295
2 Gihan Liyanage 292
3 ClimerChinna 222
4 Abhinav S 187
0 Sergey Alexandrovich Kryukov 8,213
1 OriginalGriff 7,089
2 CPallini 2,598
3 Richard MacCutchan 1,925
4 Abhinav S 1,778


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100