Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi guys!

I am trying to learn how to code in c#. Can anyone help me in this? I am trying to display data from datagridview after clicking the cell of the datagridview to the text box and combobox of another form. The following is part of code for the first 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;
using MySql.Data.MySqlClient;
namespace BasiziInformationSystem
{
    public partial class frmBasiziFaultManagement : Form
    {
        BusinessLogic.openFault view = new BusinessLogic.openFault();
        public frmBasiziFaultManagement()
        {
            InitializeComponent();
        }
        private void lblview_Click(object sender, EventArgs e)
        {
            view = new BusinessLogic.openFault();
            try
            {
                // var grd=view.bc_select();
                //  dataGridView1.DataSource=grd;
                this.selectFaultTableAdapter.Fill(this.dataSet1.selectFault);
            }
            catch (MySqlException ee)
            {
                MessageBox.Show(ee.Message.ToString());
            }
            finally
            {
                view = null;
            }
        }
        private void dataGridView1_CellClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == (dataGridView1.Columns.Count - 9))
            {
                {
                    int i = int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString());
                     updateFaults obj = new updateFaults(i);
                    obj.Show();
                }
               
                
            }
        }
    }
}

The second code is part of the code of the second 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 BasiziInformationSystem
{
    public partial class updateFaults : Form
    {
        private System.Windows.Forms.DataGridView dataGridView1=new DataGridView();
        
        public updateFaults(int i)
        {
            InitializeComponent();
            cmbclient.Text = (i).ToString();
            cmbcategory.Text =(i).ToString();
           cmbsys.Text = (i).ToString();
            cmbsite.Text =(i).ToString();
        }
       private void updateFaults_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'status.status_ids' table. You can move, or remove it, as needed.
            this.status_idsTableAdapter.Fill(this.status.status_ids);
            // TODO: This line of code loads data into the 'users.auth_users' table. You can move, or remove it, as needed.
            this.auth_usersTableAdapter.Fill(this.users.auth_users);
            // TODO: This line of code loads data into the 'site.site_ids' table. You can move, or remove it, as needed.
            this.site_idsTableAdapter.Fill(this.site.site_ids);
            // TODO: This line of code loads data into the 'system.system_ids' table. You can move, or remove it, as needed.
            this.system_idsTableAdapter.Fill(this.system.system_ids);
            // TODO: This line of code loads data into the 'faultCategories.fault_categories' table. You can move, or remove it, as needed.
            this.fault_categoriesTableAdapter.Fill(this.faultCategories.fault_categories);
            // TODO: This line of code loads data into the 'clientDetails.client_details' table. You can move, or remove it, as needed.
            this.client_detailsTableAdapter.Fill(this.clientDetails.client_details);
            dataGridView1 = new DataGridView();
            frmBasiziFaultManagement obj = new frmBasiziFaultManagement();
           // cmbclient.Text =dataGridView1.Rows[0].Cells[0].Value.ToString();
            
        }
    }
}

Please, can anyone help me with this? :(
Posted
Updated 1-Nov-10 20:44pm
v2

1. Define the Fault ID member variable in your form
2. Call the form constructor using that ID
3. Set the controls in your Form load.

Something like following:

C#
//Define the fault id member variable.
int _nFaultID = -1;//Default fault ID
public updateFaults(int i)
{
            InitializeComponent();
        _nFaultID = i;
}

private void updateFaults_Load(object sender, EventArgs e)
{
//All previous code goes above.
    cmbclient.Text = _nFaultID .ToString();
            cmbcategory.Text =_nFaultID .ToString();
           cmbsys.Text = _nFaultID .ToString();
            cmbsite.Text =_nFaultID .ToString();
}
 
Share this answer
 
v2
Comments
Dalek Dave 2-Nov-10 4:28am    
Good Call.
dominic kMalisa 2-Nov-10 4:56am    
thank you very much for your help it does work but now is it possible for it to display the rest of the data from the datagridview after clicking the specific cell
:)
<pre><pre><pre><pre><pre><pre><code><code><code><code><code><small><big><big><code>&<a href=""></a><a href=""></a>[<a href="" target="_blank"></a>]</code></big></big></small></code></code></code></code></code>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900