• 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;
      }
      }
  • 相关阅读:
    sublimetext ruby 插件
    [C]goto statement, rarely been used. Deprecated???
    [C]union
    [C] Struct Test
    [C,Java,Python]Command Line Argument: argv, argc, sys.argv, args
    [Python]**otherInfo, *other
    [C]parameterized macros 带参数的宏
    [C]指针与结构变量
    [C]结构变量传递给函数
    [C]结构变量数组array of structure varibles
  • 原文地址:https://www.cnblogs.com/beeone/p/1999320.html
Copyright © 2020-2023  润新知