Click here to Skip to main content
15,904,416 members

Comments by Zunayed Shahriar (Top 9 by date)

Zunayed Shahriar 21-May-17 5:15am View    
Great! I've always generated dropdowns from backend whether it's static or dynamic.
Zunayed Shahriar 21-May-17 1:30am View    
Can you show me your Create and Edit methods?
Zunayed Shahriar 18-May-17 6:38am View    
New full class:


public partial class Form1 : Form
{
DataGridViewCell lastCell = null;
public Form1()
{
InitializeComponent();

// LoadSerial();

}
/* private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
LoadSerial();
}*/

// int COUNTER = 0;
private void button1_Click(object sender, EventArgs e)
{


//ADDDATA(textBox2.Text, textBox1.Text);
//string EMINITIESNAME = textBox2.Text;
//string DESCRIPTION = textBox1.Text;
int row = 0;
dataGridView1.Rows.Add();
row = dataGridView1.Rows.Count -1;
dataGridView1["AMENITIESNAME", row].Value = textBox2.Text;
dataGridView1["DESCRIPTION", row].Value = textBox1.Text;
dataGridView1["SELECT", row].Value = false;
dataGridView1["AMOUNT", row].ReadOnly = true;
dataGridView1["AMOUNT", row].Style.BackColor = Color.Black;
LoadSerial();
}
private void LoadSerial()
{
int i = 1;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
row.Cells["ID"].Value = i; i++;
}

}


public void ADDDATA(string AMENITIESNAME, string DESCRIPTION)
{
int row = 0;
dataGridView1.Rows.Add();
row = dataGridView1.Rows.Count -1;
dataGridView1["AMENITIESNAME", row].Value = textBox2.Text;
dataGridView1["DESCRIPTION", row].Value = textBox1.Text;
}




private void Form1_Load(object sender, EventArgs e)
{

}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}



private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (lastCell != null)
{
var lastAmtCell = dataGridView1.Rows[lastCell.RowIndex].Cells["AMOUNT"];
if (lastAmtCell.ReadOnly == true)
{
lastCell.Value = false;
}
else
{
lastCell.Value = true;
}
}
var amountCell = dataGridView1.Rows[e.RowIndex].Cells["AMOUNT"];
if (e.RowIndex > -1 && dataGridView1.CurrentCell == dataGridView1.Rows[e.RowIndex].Cells["SELECT"])
{
if (amountCell.ReadOnly == true)
{
dataGridView1.CurrentCell.Value = true;
amountCell.ReadOnly = false;
amountCell.Style.BackColor = Color.White;
}
else
{
dataGridView1.CurrentCell.Value = false;
amountCell.ReadOnly = true;
amountCell.Style.BackColor = Color.Black;
}
lastCell = dataGridView1.CurrentCell;
}
}
}
Zunayed Shahriar 18-May-17 5:07am View    
Do not click too fast.
Change "System.Threading.Thread.Sleep(200);" to "System.Threading.Thread.Sleep(300);" to get better.
Zunayed Shahriar 18-May-17 3:27am View    
You just cannot hide a cell. What you can do is this.

Full new source:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace STS_RAM
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

// LoadSerial();

}
/* private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
LoadSerial();
}*/

// int COUNTER = 0;
private void button1_Click(object sender, EventArgs e)
{


//ADDDATA(textBox2.Text, textBox1.Text);
//string EMINITIESNAME = textBox2.Text;
//string DESCRIPTION = textBox1.Text;
int row = 0;
dataGridView1.Rows.Add();
row = dataGridView1.Rows.Count -1;
dataGridView1["AMENITIESNAME", row].Value = textBox2.Text;
dataGridView1["DESCRIPTION", row].Value = textBox1.Text;
dataGridView1["AMOUNT", row].ReadOnly = true;
dataGridView1["AMOUNT", row].Style.BackColor = Color.Black;
LoadSerial();
}
private void LoadSerial()
{
int i = 1;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
row.Cells["ID"].Value = i; i++;
}

}


public void ADDDATA(string AMENITIESNAME, string DESCRIPTION)
{
int row = 0;
dataGridView1.Rows.Add();
row = dataGridView1.Rows.Count -1;
dataGridView1["AMENITIESNAME", row].Value = textBox2.Text;
dataGridView1["DESCRIPTION", row].Value = textBox1.Text;
}




private void Form1_Load(object sender, EventArgs e)
{

}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}



private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
System.Threading.Thread.Sleep(200);
var amountCell = dataGridView1.Rows[e.RowIndex].Cells["AMOUNT"];
if (e.RowIndex > -1 && dataGridView1.CurrentCell == dataGridView1.Rows[e.RowIndex].Cells["SELECT"])
{
if (amountCell.ReadOnly == true)
{
dataGridView1.CurrentCell.Value = true;
amountCell.ReadOnly = false;
amountCell.Style.BackColor = Color.White;
}
else
{
dataGridView1.CurrentCell.Value = false;
amountCell.ReadOnly = true;
amountCell.Style.BackColor = Color.Black;
}
}
}
}
}