ma ouml

ma ouml

  • 1.7k
  • 436
  • 75.4k

How to disable or enable a link on datagridview in c #

May 16 2017 9:47 AM
Hello ,
I will rest my publication because the answers that have been proposed does not meet my need
First of all I would like to tell you that
I develop a desktop application c #
I have a form that contains textbox and I have a datagridview and it contains three links
For example I want that when I filled the textbox1 the link 2 and link 3 will be disabled
Here is the code of my form
 
 

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 ajouter_decompte : Form
{
string num_marche;
string libelle_fournisseur;
public ajouter_decompte(string num_marche, string libelle_fournisseur)
{
InitializeComponent();
textBox1.Text = num_marche;
textBox2.Text = libelle_fournisseur;
}
private void ajouter_decompte_Load(object sender, EventArgs e)
{
panel2.Visible = false;
dataGridView2.AllowUserToAddRows = false;
DataGridViewLinkColumn link1 = new DataGridViewLinkColumn();
link1.HeaderText = ""; link1.Name = "links1";
link1.Text = "Décompte provisoire";
dataGridView2.Columns.Add(link1);
link1.UseColumnTextForLinkValue = true;
DataGridViewLinkColumn link2 = new DataGridViewLinkColumn();
link2.HeaderText = "";
link2.Name = "links2";
link2.Text = "Décompte partiel";
dataGridView2.Columns.Add(link2);
link2.UseColumnTextForLinkValue = true;
DataGridViewLinkColumn link3 = new DataGridViewLinkColumn();
link3.HeaderText = "";
link3.Name = "links3";
link3.Text = "Décompte définitif";
dataGridView2.Columns.Add(link3);
link3.UseColumnTextForLinkValue = true;
}
private void button1_Click(object sender, EventArgs e)
{
Program.cmd.CommandText =
"update attachement_marche set Id_decompte =
(select top 1 Id_decompte from decompte where Num_decompte ='" + textBox3.Text + "') where Num_attachement = '" + values.num_attachement + "'";
Program.cmd.ExecuteNonQuery();
MessageBox.Show("c'est eneregistré ");
panel2.Visible = true;
Program.cmd.CommandText = " select d.Num_decompte,d.Date_etablissement,d.Flag_dernier,d.Montant_ttc from decompte d WHERE Num_decompte ='" + textBox3.Text + "'";
Program.dr = Program.cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(Program.dr);
dataGridView2.DataSource = dt;
}
private void dataGridView2_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (dataGridView2.SelectedRows.Count == 1)
{ if (dataGridView2.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
{ string cellval = dataGridView2.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
if (cellval.Contains("Décompte provisoire"))
{
etat_decompte_provisoire etd= new etat_decompte_provisoire(textBox1.Text, textBox2.Text);
etd.Show();
}
if (cellval.Contains("Décompte partiel"))
{
decompte_partiel dp = new decompte_partiel(textBox1.Text, textBox2.Text); dp.Show();
}
if (cellval.Contains("Décompte définitif"))
{
decompte_definitif dd = new decompte_definitif(textBox1.Text, textBox2.Text); dd.Show();
}
}
}
}
 
 
 
 
                                     And I would like to thank everyone who will help me
 
 
 
 
 
 

Answers (27)