Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to insert user inputed Values from Texebox and combobox to Datagrid
when we click Save Button I have done this

In my Xaml
XML
<Grid Margin="10,10,12,12">

            <DataGrid Name="customerDataGrid" CanUserAddRows="True" CanUserDeleteRows="True" Margin="34,56,237,73" AlternatingRowBackground="{x:Null}" MinRowHeight="10"></DataGrid>
            <TextBlock Height="16" HorizontalAlignment="Left" Margin="554,110,0,0" Name="textBlock1" Text="Equipment" VerticalAlignment="Top" />
            <TextBlock Height="15" HorizontalAlignment="Left" Margin="554,137,0,0" Name="textBlock2" Text="ID" VerticalAlignment="Top" />
            <TextBlock Height="15" HorizontalAlignment="Left" Margin="554,163,0,0" Name="textBlock3" Text="Start Date" VerticalAlignment="Top" />
            <TextBlock Height="16" HorizontalAlignment="Left" Margin="554,187,0,0" Name="textBlock4" Text="End Date" VerticalAlignment="Top" />
            <TextBlock Height="16" HorizontalAlignment="Left" Margin="554,211,0,0" Name="textBlock5" Text="Requsted By" VerticalAlignment="Top" />
            <TextBlock Height="16" HorizontalAlignment="Left" Margin="554,233,0,0" Name="textBlock6" Text="Purpose" VerticalAlignment="Top" />
            <TextBlock Height="17" HorizontalAlignment="Left" Margin="568,56,0,0" Name="textBlock7" Text="ADD Maintainence Shedule" VerticalAlignment="Top" FontWeight="Bold" />
            <ComboBox Height="21" HorizontalAlignment="Left" Margin="617,110,0,0" Name="comboBox1" VerticalAlignment="Top" Width="99">
                <ComboBoxItem Content="LA"/>
                <ComboBoxItem Content="CVT"/>
                <ComboBoxItem Content="Isolator"/>
                <ComboBoxItem Content="WT"/>
                <ComboBoxItem Content="ICT"/>
                <ComboBoxItem Content="CT"/>
                <ComboBoxItem Content="PT"/>
                <ComboBoxItem Content="E/S"/>
                <ComboBoxItem Content="CB"/>
                <ComboBoxItem Content="BUS" />
                <ComboBoxItem Content="CAP" />
            </ComboBox>
            <ComboBox Height="21" HorizontalAlignment="Left" Margin="618,133,0,0" Name="comboBox2" VerticalAlignment="Top" Width="99">
                <ComboBoxItem Content="29A/00"/>
                <ComboBoxItem Content="29B/00"/>
                <ComboBoxItem Content="30A/03"/>
                <ComboBoxItem Content="45B/50"/>
                <ComboBoxItem Content="39A/00"/>
                <ComboBoxItem Content="59A/00"/>
                            </ComboBox>
            <DatePicker Height="21" HorizontalAlignment="Left" Margin="618,157,0,0" Name="datePicker1" VerticalAlignment="Top" Width="99" />
            <DatePicker Height="21" HorizontalAlignment="Left" Margin="618,0,0,251" Name="datePicker2" VerticalAlignment="Bottom" Width="99" />
            <TextBox Height="21" Margin="618,208,51,0" Name="textBox1" VerticalAlignment="Top" />
            <TextBox Height="21" Margin="618,231,51,0" Name="textBox2" VerticalAlignment="Top" />
            <Button Content="Save" Height="23" HorizontalAlignment="Left" Margin="612,270,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
            <TextBlock Height="16" HorizontalAlignment="Left" Margin="554,85,0,0" Name="textBlock8" Text="BAY" VerticalAlignment="Top" />
            <ComboBox Height="21" HorizontalAlignment="Left" Margin="617,85,0,0" Name="comboBox3" VerticalAlignment="Top" Width="99">
                <ComboBoxItem Content="Kolhapur 1" />
                <ComboBoxItem Content="Kolhapur 2" />
                <ComboBoxItem Content="Kolhapur 3" />
                <ComboBoxItem Content="Kolhapur 4" />
                <ComboBoxItem Content="Vita 1" />
                <ComboBoxItem Content="Vita 2" />
                <ComboBoxItem Content="Karad 1" />
                <ComboBoxItem Content="Karad 2" />
                <ComboBoxItem Content="Miraj" />
                <ComboBoxItem Content="Pophali" />
                <ComboBoxItem Content="Pedambe" />
                <ComboBoxItem Content="Peth" />
                <ComboBoxItem Content="Koyana 1" />
                <ComboBoxItem Content="Koyana 2" />
                <ComboBoxItem Content="Lonikand" />
                <ComboBoxItem Content="Lamboti" />
            </ComboBox>
        </Grid>

and in my Xmal.cs
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 WpfApplication3
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {

        public Window1()
        {
            InitializeComponent();
            customerDataGrid.ItemsSource = LoadCollectionData();
        }
    public List<Customer> LoadCollectionData()
        {
            List<Customer> customer = new List<Customer>();

    customer.Add(new Customer()
            {
                Bay = "Kolhapur 1",
                Euqipment = "JKL",
                ID = "JKL",
                Startmdy = new Calendar(),
                Endmdy = new Calendar(),
                Purpose = "Oiling.",
                Requestedby = "Ashish.",


            });
            return customer;


        }


    }

C#
public class Customer
    {
        public string  Bay { get; set; }
        public string Euqipment { get; set; }
        public string ID { get; set; }
        public Calendar Startmdy { get; set; }
        public Calendar Endmdy { get; set; }
        public string Purpose { get; set; }
        public string Requestedby { get; set; }
        }
    }
I have Tried many ways but they are not Working Any Help even some Refrence will do
Posted
Updated 13-Feb-11 18:45pm
v4

1 solution

Hope ComboBox in a DataGrid[^]will give you an idea.
 
Share this answer
 

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