المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : C# datagridview display Question



C# Programming
07-26-2009, 05:51 PM
My Question,

I have designed FORM1 with a datagridview dgvForm1 and am populating data into it using LINQ queries. The data is populating fine into the dgvForm1.

I have a checkbox column in the dgvForm1 to select the checked rows.

I have a button in FORM1 called DISPLAY.

I have FORM2 with datagridview dgvForm2.


All I want to do is ...allow the user to select the required rows from dgvForm1 using checkboxs. After selecting, the user clicks on the DISPLAY which will show FORM2 . I want to display the selected rows from dgvForm1 in the datagridview(dgvForm2) of FORM2.

Am using C# with VS 2008 , this my code for reading the checked value of rows,,,, I have defined a constructor in Form2 to take in string values. Then in form2 initialization am assigning the string value to datagridview2 in form 2.. Am not sure if its correct to do so ..... but am not getting the required result.i.e my datagrid2 is not getting populate with the checked rows from datagrid1. please suggest solutions,,,thanks


string

data = string.Empty;
//data = this
foreach (DataGridViewRow row in dataGridView1.Rows
{
if (row.Cells[SelectColumnIndex].Value != null &&
Convert.ToBoolean(row.Cells[SelectColumnIndex].Value) == true)
{
foreach (DataGridViewCell cell in row.Cells)
{
if (cell.OwningColumn.Index != SelectColumnIndex)
{
data += (cell.Value + ",");
}
}
data += "\n";
}
}
Form2 fm = new Form2(data);
fm.Show();

}


public Form2(String data)

{

InitializeComponent();

this.dgv1Fm2.DataSource = data;





}