C#: How to retrieve text from dgView cell and displayit in the button?
-
Hello everyone I have posted a question yesterday but no one seems to answer my question. I thought that the Code Project Forum is there for people to help who dont have much knowledge on programming... Kind Regards Roni
First, this is a volunteer effort. The regulars who come here to answer questions do so on THEIR time, not yours. If you want answers to your questions on your schedule, call up Microsoft and pay for the support. What you just did with your post here is extremely rude.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Hello everyone I have posted a question yesterday but no one seems to answer my question. I thought that the Code Project Forum is there for people to help who dont have much knowledge on programming... Kind Regards Roni
create an event for the gridview like so; private void dgv_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { //runs when the mouse is clicked over a cell if (e.RowIndex > -1 && e.ColumnIndex > -1) { if (e.Button == MouseButtons.Left) { //single-click left mouse button if (dgv.SelectionMode != DataGridViewSelectionMode.CellSelect) { dgv.SelectionMode = DataGridViewSelectionMode.CellSelect; int row = dgv.CurrentCell.RowIndex; int col = dgv.CurrentCell.ColumnIndex; } } textbox.text=dgv.Rows[row].Cells[col].Value.ToString(); } Remeber to Create the same event in the Form.Designer.cs file for the Datagridview. Hope this Helps
-
Hello everyone I have posted a question yesterday but no one seems to answer my question. I thought that the Code Project Forum is there for people to help who dont have much knowledge on programming... Kind Regards Roni
LAPEC wrote:
no one seems to answer my question
There could be a number of reasons for that: 1) No body knew the answer. 2) No body could be bothered to work out what the question was, because of the large lump of code they didn't want to bother with. 3) You didn't seem to have shown much effort in working on your problem yourself. 4) Some combination of the above. You have to remember: not everybody looks at Q&A; nobody here gets paid for this; most of us have jobs which do pay and expect a certain amount of work from us. You aren't helping yourself by taking a whining, petulant tone in your "bump" message...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
Hello everyone I have posted a question yesterday but no one seems to answer my question. I thought that the Code Project Forum is there for people to help who dont have much knowledge on programming... Kind Regards Roni
LAPEC wrote:
I thought that the Code Project Forum is there for people to help who dont have much knowledge on programming...
It's a forum, people meet. Sometimes they help each other, but being a member is no replacement for an education.
I are Troll :suss:
-
create an event for the gridview like so; private void dgv_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { //runs when the mouse is clicked over a cell if (e.RowIndex > -1 && e.ColumnIndex > -1) { if (e.Button == MouseButtons.Left) { //single-click left mouse button if (dgv.SelectionMode != DataGridViewSelectionMode.CellSelect) { dgv.SelectionMode = DataGridViewSelectionMode.CellSelect; int row = dgv.CurrentCell.RowIndex; int col = dgv.CurrentCell.ColumnIndex; } } textbox.text=dgv.Rows[row].Cells[col].Value.ToString(); } Remeber to Create the same event in the Form.Designer.cs file for the Datagridview. Hope this Helps
Hi Enobong Adahada thanks for replying to my message, I have managed to work around my code refering to the question I posted yesterday but for some reason its not getting the cell value number to display it in the button. If you dont mind please you can have a look my question (under the View Unanswered Question) provided with sample of code and tell me if I missing something.... Thanks in advance kind regards roni
-
Hi Enobong Adahada thanks for replying to my message, I have managed to work around my code refering to the question I posted yesterday but for some reason its not getting the cell value number to display it in the button. If you dont mind please you can have a look my question (under the View Unanswered Question) provided with sample of code and tell me if I missing something.... Thanks in advance kind regards roni
Can you post the code u are using so i can see if there are logic bugs.
-
Can you post the code u are using so i can see if there are logic bugs.
Here is the code... I have two forms on my project (Form1 & Form2). -In Form1 I have two Buttons (Starter & Main). Both these buttons on click event, they call database sql-query and genereate into form the records as Buttons. -In Form2 I have a Button (Starter) and DataGridView. Also this button on click event calls database sql-query and generates records in DatagridView. DataGridView has four columns: (Note: On columns [0] and [1] data are genereated from database, the columns [2] and [3] are template columns genereated at run-time also filled with data at run-time) Now in Form2 when I double_click inside the Cell under the Qty In Stock column, a dialog-box pops up and allows me to enter the number in to that particular cell. Lets say Row-1: like so...
FoodName FoodType Qty In Stock Status
Soup Starter 10 Allways On Stock
Based on this: How can I take the value of that cell = 10 and dispalyit on the bottom-right corner of the Button (in this case button Soup). This is what the Soup Button should look like (in Form1): (Note: The Button called Soup is generated from database...)
##############
Soup
10
##############
Here is the code of dataGridView1_CellClick event (in Form2)...
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 2)
{
// Value is given in case the cell is empty
string cellContent = "0";
if (this.dataGridView1[e.ColumnIndex, e.RowIndex].Value != null)
{
cellContent = this.dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
}using (InputBox ib = new InputBox("Enter new stock amount:", this.dataGridView1\[0, e.RowIndex\].Value.ToString(), cellContent)) { if (ib.ShowDialog() == DialogResult.OK) { this.dataGridView1\[e.ColumnIndex, e.RowIndex\].Value = ib.Result; cellContent = ib.Result; } } } }
This is the code of InputBox dialog where it allows me to enter quantity in to the Cell of dataGridView1...
public partial class InputBox : Form
{
public InputBox(string tex -
Here is the code... I have two forms on my project (Form1 & Form2). -In Form1 I have two Buttons (Starter & Main). Both these buttons on click event, they call database sql-query and genereate into form the records as Buttons. -In Form2 I have a Button (Starter) and DataGridView. Also this button on click event calls database sql-query and generates records in DatagridView. DataGridView has four columns: (Note: On columns [0] and [1] data are genereated from database, the columns [2] and [3] are template columns genereated at run-time also filled with data at run-time) Now in Form2 when I double_click inside the Cell under the Qty In Stock column, a dialog-box pops up and allows me to enter the number in to that particular cell. Lets say Row-1: like so...
FoodName FoodType Qty In Stock Status
Soup Starter 10 Allways On Stock
Based on this: How can I take the value of that cell = 10 and dispalyit on the bottom-right corner of the Button (in this case button Soup). This is what the Soup Button should look like (in Form1): (Note: The Button called Soup is generated from database...)
##############
Soup
10
##############
Here is the code of dataGridView1_CellClick event (in Form2)...
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 2)
{
// Value is given in case the cell is empty
string cellContent = "0";
if (this.dataGridView1[e.ColumnIndex, e.RowIndex].Value != null)
{
cellContent = this.dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
}using (InputBox ib = new InputBox("Enter new stock amount:", this.dataGridView1\[0, e.RowIndex\].Value.ToString(), cellContent)) { if (ib.ShowDialog() == DialogResult.OK) { this.dataGridView1\[e.ColumnIndex, e.RowIndex\].Value = ib.Result; cellContent = ib.Result; } } } }
This is the code of InputBox dialog where it allows me to enter quantity in to the Cell of dataGridView1...
public partial class InputBox : Form
{
public InputBox(string texReason for my vote of 1: Why cut and paste that lot? Why did you not just give a link to your Q&A question? Now, you have two places with the same info, that potentially could duplicate work if anyone does answer. :doh:
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.