ma ouml

ma ouml

  • NA
  • 436
  • 88.4k

How to select a line in datagridview in c#

Mar 14 2017 8:21 AM
How to select a line in datagridview
Here is my code of the interface that I treat
 
 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace gestion_attachements_decomptes

{

public partial class choisir_marche : Form

{

public choisir_marche()

{

Program.con.Close();

Program.con.Open();

Program.cmd.Connection = Program.con;

InitializeComponent();

}

private void marche_Load(object sender, EventArgs e)

{

Program.cmd.CommandText = "select m.Num_marche, f.Libelle_fournisseur from marche m , fournisseur f ,autorisation a where f.Id_fournisseur =m.Id_fournisseur and m.Id_site = a.Id_site and a.Id_user in (select Id_user from utilisateur where User_name = '" + values.username + "')";

Program.dr = Program.cmd.ExecuteReader();

DataTable dt = new DataTable();

dt.Load(Program.dr);

dataGridView1.DataSource = dt;

dataGridView1.AllowUserToAddRows = false;

}

private void button4_Click(object sender, EventArgs e)

{

liste_attachement lia = new liste_attachement(textBox1.Text, textBox2.Text);

lia.Show();

}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)

{

if (e.RowIndex >= 0)

{

DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];

textBox1.Text = row.Cells["Num_marche"].Value.ToString();

textBox2.Text = row.Cells["Libelle_fournisseur"].Value.ToString();

}

}

}

}

 
 
 
And thanks in advance  
 
 
 

Answers (4)