本文介绍了如何将用户输入的值从Texebox和combobox插入到Datagrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将用户输入的值从Texebox和combobox插入到Datagrid
当我们单击保存"按钮时,我已经完成了此操作

在我的Xaml中

How to insert user inputed Values from Texebox and combobox to Datagrid
when we click Save Button I have done this

In my Xaml

<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


and in my Xmal.cs

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;


        }


    }


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

推荐答案


这篇关于如何将用户输入的值从Texebox和combobox插入到Datagrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 08:28