Click here to Skip to main content
16,016,168 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..
I have three textboxes where i enter first name, middle name and last name and save and edit button. After i save that into db,i retrive from the database and bind to datagridview. I want to merge those three columns as one. And when i click edit button....first,middle and last names should be filled in the corresponding textboxes.

How can i achieve this.
Posted

I don't know what kind of database you use, but can't you do something like

"SELECT (Firstname + Middlename + Lastname) AS fullname from [... etc]"

That way you'll receive all 3 columns into one column directly from the datasource.

Then when you click the edit button just select the data separate again, into the textboxes
 
Share this answer
 
Comments
ashu2188 17-Jul-10 15:26pm    
thats the way you can do that...!!! i also do the same way.
Actually i am trying to learn how we can merge datagridview columns.
I know your proposed method, thank you.
 
Share this answer
 
Oke, if you really want to "merge them" you could do

C#
private void DataGridView_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
    foreach (DataGridViewRow row in DataGridView.Rows)
    {
    row.Cells["Firstname"].value += row.Cells["Middlename"].value.ToString() + row.Cells["Lastname"].value.ToString();
    }
    DataGridViewRow.Columns["Middlename"].Visible = false;
    DataGridViewRow.Columns["Lastname"].Visible = false;
}
 
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