zoukankan      html  css  js  c++  java
  • DataGridView 为TextBox初始化,单击事件

    /*
    * 窗体描述:显示“长春市六条主要江河八五年洪水情况表”信息;
    * 功能: ;
    * 方法:GetRiverString();//根据传参“河流名称”“数据库连接串”进行查询
    * 作者: HeTao
    * 日期: 2011-03-12, 星期六
    * 版本:V1.0
    *
    * 修改人员:
    * 修改日期:
    * 修改内容:
    */
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;

    namespace YNRBSYS.RiversInfoQuery
    {
    public partial class uc_6JL85HS : UserControl
    {

    /// <summary>
    ///
    /// </summary>
    /// <param name="RiverName">河流名称</param>
    /// <param name="connString">数据库连接串</param>

    public void GetRiverString(string RiverName, string connString)
    {
    try
    {
    SqlConnection conn
    = new SqlConnection(connString);

    conn.Open();

    string SqlStr = "SELECT * from CC_RIVER_HSXX "+
    "WHERE (RIVERCODE ='" + RiverName + "')";

    DataSet ds
    = new DataSet();

    SqlDataAdapter sda
    = new SqlDataAdapter();

    sda.SelectCommand
    = new SqlCommand(SqlStr, conn);

    sda.Fill(ds,
    "info");

    SqlCommand scmd
    = new SqlCommand(SqlStr, conn);

    SqlDataReader objSqlReader
    = scmd.ExecuteReader();

    while (objSqlReader.Read())
    {

    dataGridViewX1.DataSource
    = ds.Tables[0];

    }

    }
    catch (Exception ex)
    {

    MessageBox.Show(ex.Message);

    }

    }

    private void setDataGridViewString()
    {
    if (dataGridViewX1.SelectedRows.Count > 0)
    {
    int i = dataGridViewX1.SelectedRows[0].Index;

    txtHSNF.Text
    = dataGridViewX1.Rows[i].Cells[1].Value.ToString();

    txtHLMC.Text
    = dataGridViewX1.Rows[i].Cells[2].Value.ToString();

    txtXQ.Text
    = dataGridViewX1.Rows[i].Cells[4].Value.ToString();

    txtZDSW.Text
    = dataGridViewX1.Rows[i].Cells[5].Value.ToString();

    txtZM.Text
    = dataGridViewX1.Rows[i].Cells[3].Value.ToString();

    txtZDLL.Text
    = dataGridViewX1.Rows[i].Cells[6].Value.ToString();

    txtFSSJ.Text
    = dataGridViewX1.Rows[i].Cells[7].Value.ToString();

    txtDWZYQKXZ.Text
    = dataGridViewX1.Rows[i].Cells[8].Value.ToString();

    txtDWZYQKZRT.Text
    = dataGridViewX1.Rows[i].Cells[9].Value.ToString();

    txtDWZYQKHS.Text
    = dataGridViewX1.Rows[i].Cells[10].Value.ToString();

    txtDWZYQKRK.Text
    = dataGridViewX1.Rows[i].Cells[11].Value.ToString();

    txtDWZYQKFW.Text
    = dataGridViewX1.Rows[i].Cells[12].Value.ToString();

    txtDWZYQKGD.Text
    = dataGridViewX1.Rows[i].Cells[13].Value.ToString();

    txtBZ.Text
    = dataGridViewX1.Rows[i].Cells[14].Value.ToString();
    }
    }
    public uc_6JL85HS()
    {

    InitializeComponent();

    }
    //dataGridView 为textbox初始化值
    private void uc_6JL85HS_Load(object sender, EventArgs e)
    {

    setDataGridViewString();

    }

    private void dataGridViewX1_CellClick(object sender, DataGridViewCellEventArgs e)
    {

    setDataGridViewString();

    }
    }
    }
  • 相关阅读:
    python,jsonpath提取json数据
    [.Net] Web API 本地化与全球化
    缺省源
    组合恒等式
    20210925衡阳八中多校联测
    codeforces赛后总结——1556D. Take a Guess
    codeforces赛后总结——1556C. Compressed Bracket Sequence
    阿里云(Ubuntu20.04)搭建wordpress全流程——附图超详细版
    Linux常用命令行操作
    阿里云服务器增加监听端口
  • 原文地址:https://www.cnblogs.com/beeone/p/2000031.html
Copyright © 2011-2022 走看看