码迷,mamicode.com
首页 > Windows程序 > 详细

DataGridView

时间:2015-07-03 13:55:56      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using APPcarDA;
using APPcarfangfa;

namespace WindowsFormsApplication2
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            List<DA> list = new fangfa().select();
            dataGridView1.AutoGenerateColumns = false;//自动生成列
            dataGridView1.DataSource = list;//自动添加
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show( dataGridView1.SelectedCells[0].Value.ToString());//获取选中的单元格。选中的单元格的集合,最后选中的单元格在最前面
            dataGridView1.SelectedRows[0].Cells[0].Value.ToString();//选中的行集合,可以根据选中的行具体到这一行的任一单元格
            DA car=(DA) dataGridView1.SelectedRows[0].DataBoundItem;//将某一行直接转换成对象
            MessageBox.Show(car.Oil.ToString());
        }
    }
}

 

DataGridView

标签:

原文地址:http://www.cnblogs.com/dlexia/p/4618402.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!