Click here to Skip to main content
15,917,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to pass a textbox's value (place on a window form) to a datagridview's selected row (place on another window form) on a click event of a button in window application.
give me a suitable answer plz..
Posted
Updated 14-Jun-11 20:21pm
v2
Comments
[no name] 15-Jun-11 2:15am    
post what you have done so far, let us take a look and correct the mistake.
Also Tag your question to Windows, web etc...
RaviRanjanKr 15-Jun-11 2:34am    
give us a suitable effort please :)

You can't change what gets passed in the existing event. You'll need to write your own event, or generally write your own code to respond to the existing event, with the values you're looking for.
 
Share this answer
 
Your question is not clear, but i'm posting portion of code that may help you......
C#
if (dataGridView1.DataSource != null)
{
    DataTable dt = (DataTable)dataGridView1.DataSource;
    if (dataGridView1.SelectedRows.Count <= 0) { return; }
    if (dt.Rows.Contains(dataGridView1.SelectedRows[0]))
    {
        DataRow[] dr = dt.Rows.Find(dt.Rows[0]["fieldname"]);
        if (dr.Length <= 0) return;
        //change the value of datarow
        dr[1] = txtName.Text; //  set related value
        dr[2] = txtcity.Text; //  set related value
        // now accept the change...
        dt.AcceptChanges();
        dataGridView1.Refresh();
    }
}
 
Share this answer
 
There are so many options... and yes, you should have provided more information :). Do you really have to use click event?
If yes - create a new event in your "edit" form, pass textbox's value as an argument and subscribe to this event in form with datagridview. Or you can pass a reference to your datagridview in "edit" form constructor/custom show method, though I strongly recommend you to avoid this practice at all costs.
If you just need to set value in your form - ie "edit" form is modal or may be made so - well, just return new text value via constructor/custom display method
 
Share this answer
 
Add this method in your form which contains DatagridView

public void populateGrid(string text)
{
DataGridViewRowCollection rows = this.dataGridView1.Rows;
rows.Add(text);
}

and call this method from the form which consists your textbox.

May b this can help you.
 
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