在datagrid中插入更新删除 [英] Insert update delete in datagrid

查看:64
本文介绍了在datagrid中插入更新删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows应用程序中进行学校软件项目.在学生评分表加载中
我想一次加载特定班级的所有学生分数的表格
我正在使用datagrid获取学生姓名和科目.现在我要输入
学生在数据网格中打分并计算总数和平均值.我不知道
如何在datagrid中动态输入值并将其插入数据库.

我正在使用sqlserver 2005作为后端

如果有人通过一些示例代码或链接与我分享想法.

I am doing school software project in windows application.in student marksheet loading
form i want to load the all the student marks for particular class at one instant
i am using datagrid to get the student name and subject.now i want to enter the
student marks within the datagrid and calculate the total and average.i don''t know
how to enter the values dynamically in datagrid and insert it into the database.

i am using sqlserver 2005 as backend

if anyone have an idea share with me with some example code or link.

推荐答案

以下是示例代码

在行"Data"中定义要嵌入的数据
Here is the sample code

Data to be embedded in a row is defined in the class ''Data''
public class Data
{
    public string Name { get; set; }
}



XAML前端代码将为:



XAML front end code will be:

<UserControl .... xmlns:my="clr-namespace:System.Windows.Controls; assembly=System.Windows.Controls.Data>...
<my:DataGrid x:Name="dg" AutoGenerateColumns="True"></my:DataGrid>
<TextBox x:Name="Nametxt" />
<Button Content="Add" Click="Btn_click"/>



C#背后的代码是



Code behind C# is

List<data> source = new List<data>();
dg.ItemsSource = source;

void Btn_Click(...)
{
        source.Add(new Data()
        { 
            Name = Nametxt.Text.Trim();
        });
}</data></data>


在发布问题之前,您应该做一些研究.
参见



或仅使用搜索选项或
You should do a bit of research before posting a question.
See
this,
this,
this,
or just use search option or google it!

Learning is a process, shortcuts aren''t always best solution.


这篇关于在datagrid中插入更新删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆