Hi,
I have a datagridview in form1. I want that the values from the datagridview shows up in an another form named 'edit'. I have done textboxes in form named 'edit' so I can see the values from datagridview.

Check this image it maybe helps you understand better.
http://img532.imageshack.us/img532/5362/inventoryvalue.jpg

hey it like this


int i = dgvProposalInProgress.SelectedCells[0].RowIndex;

topicNo = dgvProposalInProgress.Rows.Cells[0].Value.ToString();//this is the unique key in my database wich is taken from the database, topic number is defined glbally

new frmViewProposalInProgress().Show();

in the next form u need to open get that global key and select the appropriate data from the database and display in the text boxes.
hope u got w@ i am saying.
if not just ask again

hey by the way can i have u'r code for the two forms u have created, i am alos in a problem in datagrid view

appriciate a lot thanxxxxxxxxxxxx

The easiest way to accomplish this is if the datagridview data is based on an underlying data table. This data table would require a key or unique field. When you click the "Edit" button you could pass this value to the constructor of the "Edit" form and then look up the desired record from the underlying data table. Here is how you could look up the desired record (using linq -- you will need a reference to System.Data.DataSetExtensions -- should be added by default -- VS2008)

IEnumerable<DataRow> query = from DataRow order in ds1.tblDssDetail2.AsEnumerable()
 where (int)order["rowID"] == yourUniqueValue
 select order;

DataTable dt = query.CopyToDataTable<DataRow>();
DataRow dr1 = dt.Rows[0];
//--now populate your textboxes

foreach (DataColumn dc in dt.Columns)
{
   Console.WriteLine(dr1[dc.ColumnName].ToString());
}

Hi,
I have a datagridview in form1. I want that the values from the datagridview shows up in an another form named 'edit'. I have done textboxes in form named 'edit' so I can see the values from datagridview.

Check this image it maybe helps you understand better.
http://img532.imageshack.us/img532/5362/inventoryvalue.jpg

Can somebody tell me where I should put rpng's code in my code.

Here is the code for my forms. Krisnisilva yes you can use it.

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 ProjektBildelar
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            new Form2().Show();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'partsDataSet.partsTable' table. You can move, or remove it, as needed.
            this.partsTableTableAdapter.Fill(this.partsDataSet.partsTable);

        }

        private void updateButton_Click(object sender, EventArgs e)
        {
            this.partsTableTableAdapter.Fill(this.partsDataSet.partsTable);

            MessageBox.Show("Updated");

        }

        private void makeBox_TextChanged(object sender, EventArgs e)
        {
            DataView Dv = new DataView();

            Dv.Table = partsDataSet.Tables["partsTable"];
            Dv.RowFilter = " Make LIKE '%" + makeBox.Text + "%' AND Model LIKE '%" + modelBox.Text + "%' AND Part LIKE '%" + partBox.Text + "%' AND Description LIKE '%" + descriptionBox.Text + "%' ";
            dataGridView1.DataSource = Dv;
            
        }

        private void modelBox_TextChanged(object sender, EventArgs e)
        {
            DataView Dv = new DataView();

            Dv.Table = partsDataSet.Tables["partsTable"];
            Dv.RowFilter = " Make LIKE '%" + makeBox.Text + "%' AND Model LIKE '%" + modelBox.Text + "%' AND Part LIKE '%" + partBox.Text + "%' AND Description LIKE '%" + descriptionBox.Text + "%' ";
            dataGridView1.DataSource = Dv;

        }

        private void partBox_TextChanged(object sender, EventArgs e)
        {
            DataView Dv = new DataView();

            Dv.Table = partsDataSet.Tables["partsTable"];
            Dv.RowFilter = " Make LIKE '%" + makeBox.Text + "%' AND Model LIKE '%" + modelBox.Text + "%' AND Part LIKE '%" + partBox.Text + "%' AND Description LIKE '%" + descriptionBox.Text + "%' ";
            dataGridView1.DataSource = Dv;
        }

        private void descriptionBox_TextChanged(object sender, EventArgs e)
        {
            DataView Dv = new DataView();

            Dv.Table = partsDataSet.Tables["partsTable"];
            Dv.RowFilter = " Make LIKE '%" + makeBox.Text + "%' AND Model LIKE '%" + modelBox.Text + "%' AND Part LIKE '%" + partBox.Text + "%' AND Description LIKE '%" + descriptionBox.Text + "%' ";
            dataGridView1.DataSource = Dv;
        }

        private void clearBt_Click(object sender, EventArgs e)
        {
            makeBox.Text = "";
            modelBox.Text = "";
            partBox.Text = "";
            descriptionBox.Text = "";
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            new Edit().Show();
        }
    }
}
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 ProjektBildelar
{
    public partial class Edit : Form
    {
        public Edit()
        {
            InitializeComponent();
        }

        private void makeBox_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void Edit_Load(object sender, EventArgs e)
        {

        }
    }
}

In the form that contains the datagridview -- in the cellClick event

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == (dataGridView1.Columns.Count-1))
{
  int i = dgrv1.Rows[e.RowIndex].Cells["yourUniqueID"].Value;
  frmEdit frm = new frmEdit(i);  //--pass the unique row ID to the constructor of frmEdit
  frm.Show();
}

Can somebody tell me where I should put rpng's code in my code.

Here is the code for my forms. Krisnisilva yes you can use it.

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 ProjektBildelar
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            new Form2().Show();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'partsDataSet.partsTable' table. You can move, or remove it, as needed.
            this.partsTableTableAdapter.Fill(this.partsDataSet.partsTable);

        }

        private void updateButton_Click(object sender, EventArgs e)
        {
            this.partsTableTableAdapter.Fill(this.partsDataSet.partsTable);

            MessageBox.Show("Updated");

        }

        private void makeBox_TextChanged(object sender, EventArgs e)
        {
            DataView Dv = new DataView();

            Dv.Table = partsDataSet.Tables["partsTable"];
            Dv.RowFilter = " Make LIKE '%" + makeBox.Text + "%' AND Model LIKE '%" + modelBox.Text + "%' AND Part LIKE '%" + partBox.Text + "%' AND Description LIKE '%" + descriptionBox.Text + "%' ";
            dataGridView1.DataSource = Dv;
            
        }

        private void modelBox_TextChanged(object sender, EventArgs e)
        {
            DataView Dv = new DataView();

            Dv.Table = partsDataSet.Tables["partsTable"];
            Dv.RowFilter = " Make LIKE '%" + makeBox.Text + "%' AND Model LIKE '%" + modelBox.Text + "%' AND Part LIKE '%" + partBox.Text + "%' AND Description LIKE '%" + descriptionBox.Text + "%' ";
            dataGridView1.DataSource = Dv;

        }

        private void partBox_TextChanged(object sender, EventArgs e)
        {
            DataView Dv = new DataView();

            Dv.Table = partsDataSet.Tables["partsTable"];
            Dv.RowFilter = " Make LIKE '%" + makeBox.Text + "%' AND Model LIKE '%" + modelBox.Text + "%' AND Part LIKE '%" + partBox.Text + "%' AND Description LIKE '%" + descriptionBox.Text + "%' ";
            dataGridView1.DataSource = Dv;
        }

        private void descriptionBox_TextChanged(object sender, EventArgs e)
        {
            DataView Dv = new DataView();

            Dv.Table = partsDataSet.Tables["partsTable"];
            Dv.RowFilter = " Make LIKE '%" + makeBox.Text + "%' AND Model LIKE '%" + modelBox.Text + "%' AND Part LIKE '%" + partBox.Text + "%' AND Description LIKE '%" + descriptionBox.Text + "%' ";
            dataGridView1.DataSource = Dv;
        }

        private void clearBt_Click(object sender, EventArgs e)
        {
            makeBox.Text = "";
            modelBox.Text = "";
            partBox.Text = "";
            descriptionBox.Text = "";
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            new Edit().Show();
        }
    }
}
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 ProjektBildelar
{
    public partial class Edit : Form
    {
        public Edit()
        {
            InitializeComponent();
        }

        private void makeBox_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void Edit_Load(object sender, EventArgs e)
        {

        }
    }
}

I put the code here but it shows error. And what code should i put in the textbox so the values shows up.

The error is:
cannot implicitly convert type 'objekt' to 'int'. An explicit conversion exists (are you missing a cast?)

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == (dataGridView1.Columns.Count - 1))
            {
                int i = dataGridView1.Rows[e.RowIndex].Cells["yourUniqueID"].Value;
                frmEdit frm = new frmEdit(i); //--pass the unique row ID to the constructor of frmEdit
                frm.Show();
            }
        }

Use this:

int i = (int)dataGridView1.Rows[e.RowIndex].Cells["yourUniqueID"].Value;

Thanks

Use this:

int i = (int)dataGridView1.Rows[e.RowIndex].Cells["yourUniqueID"].Value;

Thanks

Can you please help me again. It shows also this error:

The type or namespace name 'frmEdit' could not be found (are you missing a using directive or an assembly reference?)

I use right now form1 and an another form named Edit. Can you also tell me the code I should use in my textbox so the value shows up. And what should I right in ["yourUniqueID"].

You might have misspelled the name of that FormEdit form. Can you post your code?

Thanks

Here is my code

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == (dataGridView1.Columns.Count - 1))
            {
            int i = (int)dataGridView1.Rows[e.RowIndex].Cells["yourUniqueID"].Value;
            frmEdit frm = new frmEdit(i); //--pass the unique row ID to the constructor of frmEdit
            frm.Show();
            }
        }

OK. It would look something like this:

In the form containing your datagridview you have this:

private void dgrv1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//--pick the cell that contains your row ID value -- I use cell 25. If your cell
//--is cell 0 then put a 0 where I have 25 -- note: cells start at 0
int i = (int)dgrv1.Rows[e.RowIndex].Cells[25].Value;
Form3 frm = new Form3(i);
frm.Show();
}


-- and in the form with the textboxes (you have to call your form -- not my form) in the constructor you will initial a form level int var (which I named s here)

public partial class Form3 : Form
{
int s;
public Form3(int t)
{
InitializeComponent();
s = t;
}
...

Then use s in the linq query I provided earlier to retrieve your desired record. Then use a DataRow object to retrieve the values from this record:

IEnumerable<DataRow> query2 =
from DataRow order in ds1.tblDssDetail2.AsEnumerable()
where (int)order["rowID"] == s
select order;

DataTable dt = query2.CopyToDataTable<DataRow>();
DataRow dr1 = dt.Rows[0];
txt1.Text = dr1["fld1"].ToString();
txt2.Text = dr1["fld2"].ToString();
txt3.Text = dr1["fld3"].ToString();
...

Here is my code

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == (dataGridView1.Columns.Count - 1))
            {
            int i = (int)dataGridView1.Rows[e.RowIndex].Cells["yourUniqueID"].Value;
            frmEdit frm = new frmEdit(i); //--pass the unique row ID to the constructor of frmEdit
            frm.Show();
            }
        }

Are you sure you've spelled frmEdit correctly? And is it under the same namespace as the current form?

The code below shows error and the error is: The name 'ds1' does not exist in the current context.
My dataset name is partsDataSet and i put that instead of ds1 but it shows another error wich have to do with tblDssDetail2.
Can somebody explain what ds1 and tblDssDetail2 is and how I can solve it.

IEnumerable<DataRow> query2 = from DataRow order in ds1.tblDssDetail2.AsEnumerable()
                                          where (int)order[0] == s
                                          select order;

            DataTable dt = query2.CopyToDataTable<DataRow>();
            DataRow dr1 = dt.Rows[0];

Could somebody help me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.