zoukankan      html  css  js  c++  java
  • dataGridView 单机提数据到TextBox

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

    namespace TestOne
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    public void SetDateSet(string xing, string ConnStr)
    {
    string SqlStr = "SELECT * FROM T_UserName WHERE(Xing='"+xing+"')";
    string connStr = ConnStr;
    SqlConnection conn
    = new SqlConnection(connStr);
    conn.Open();
    SqlCommand cmd
    = conn.CreateCommand();
    cmd.CommandText
    = SqlStr;

    SqlDataAdapter adp
    = new SqlDataAdapter(cmd);
    DataTable dt
    = new DataTable();
    adp.Fill(dt);
    dataGridViewX1.DataSource
    = dt;


    }

    private void Form1_Load(object sender, EventArgs e)
    {

    textBoxX1.Text
    = dataGridViewX1.Rows[0].Cells[1].Value.ToString().Trim();
    textBoxX2.Text
    = dataGridViewX1.Rows[0].Cells[2].Value.ToString().Trim();

    }


    private void dataGridViewX1_CellClick(object sender, DataGridViewCellEventArgs e)
    {
    if (dataGridViewX1.Rows.Count > 0)
    {
    int i = dataGridViewX1.SelectedRows[0].Index;
    textBoxX1.Text
    = dataGridViewX1.Rows[i].Cells[1].Value.ToString().Trim();
    textBoxX2.Text
    = dataGridViewX1.Rows[i].Cells[2].Value.ToString().Trim();

    }
    }

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


    namespace TestOne
    {
    public partial class Test : Form
    {
    public Test()
    {
    InitializeComponent();
    }

    private void buttonX1_Click(object sender, EventArgs e)
    {
    Form1 f
    = new Form1();
    f.SetDateSet(
    "", "Data Source=.;Initial Catalog=TestDB;Integrated Security=True");
    f.Show();


    }



    }

    }

    dataGridview 间隔着现实红格子

    以下是引用片段:
    if (this.dataGridView1.Rows.Count != 0)
      {
      
    for (int i = 0; i < this.dataGridView1.Rows.Count; )
      {
      
    this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;
      i
    += 2;
      }
      }
  • 相关阅读:
    简明Python3教程 12.问题解决
    简明Python3教程 11.数据结构
    【SPOJ 694】Distinct Substrings
    【codeforces Manthan, Codefest 17 C】Helga Hufflepuff's Cup
    【CF Manthan, Codefest 17 B】Marvolo Gaunt's Ring
    【CF Manthan, Codefest 17 A】Tom Riddle's Diary
    【SPOJ 220】 PHRASES
    【POJ 3261】Milk Patterns
    【POJ 3294】Life Forms
    【POJ 1226】Substrings
  • 原文地址:https://www.cnblogs.com/beeone/p/1999320.html
Copyright © 2011-2022 走看看