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;
      }
      }
  • 相关阅读:
    滑动最小值 /// 单调队列
    Largest Rectangle in a Histogram /// 单调栈 oj23906
    能量项链 /// oj23800
    Traveling by Stagecoach /// 状压DP oj22914
    Hamilton回路 旅行商TSP问题 /// dp oj1964
    最难的工作 /// SPFA模板 oj1396
    次短路 /// dijkstra oj1597
    USACO 2006 November Gold Fence Repair /// 贪心(有意思)(优先队列) oj23940
    石子合并问题 /// 区间DP oj2025
    多边形游戏 /// 区间DP oj1903
  • 原文地址:https://www.cnblogs.com/beeone/p/1999320.html
Copyright © 2011-2022 走看看