Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 1-Nov-10 20:42pm
Edited 1-Nov-10 20:44pm
JF201553.1K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
 
//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();
}
  Permalink  
v2
Comments
Dalek Dave at 2-Nov-10 4:28am
   
Good Call.
dominic kMalisa at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Smile | :)
<pre><pre><pre><pre><pre><pre><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>
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 13 Jan 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100