16,014,677 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
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;
}
}
}
}
}
Zunayed Shahriar
18-May-17 2:36am
View
New Changes
New Method:
private void ResetSelection()
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
row.Cells["SELECT"].Value = false;
}
}
Changed Methods:
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.Columns["AMOUNT"].Visible = false;
LoadSerial();
ResetSelection();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
System.Threading.Thread.Sleep(200);
if (e.RowIndex > -1 && dataGridView1.CurrentCell == dataGridView1.Rows[e.RowIndex].Cells["SELECT"])
{
ResetSelection();
if (dataGridView1.Columns["AMOUNT"].Visible == false)
{
dataGridView1.CurrentCell.Value = true;
dataGridView1.Columns["AMOUNT"].Visible = true;
}
else
{
dataGridView1.Columns["AMOUNT"].Visible = false;
dataGridView1.CurrentCell.Value = false;
}
}
}
Try this. If there is any problem, then let me know.
Zunayed Shahriar
18-May-17 2:32am
View
You're most welcome
Zunayed Shahriar
18-May-17 1:32am
View
See, the source link... You'll get the full conversation.
Zunayed Shahriar
17-May-17 7:45am
View
Deleted
Show More