Hi all,

I'm working on a problem where I have to store,retrieve, update the data from some temporary variables (for e.g. array)

The scenario is as follows.

Assume I have a datagridview with n number of rows and 3 columns

for e.g.

Id  name      class

1   ff             2

2   rr             3

I have other text boxes where the data (such as ranks, marks etc.) for each row is enetered

by clicking on the rows in the datagridview the data for that id has to be stored. And also should be able to retrieve and show in their respective text boxes, if there is a change then it should be updated in the storage variable. At the end all the data in the variable should be saved in the database (I'm able to do this by myself).

To achieve this I used the

private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)


and to store the data from the textboxes I used two dimensional array.

for (int i = 0; i < list.Length; i++)
                        if ((list[i, 0] == row.Cells[0].Value.ToString()) && (list[i, 1] == row.Cells[2].Value.ToString()))
                            richTextBox14.Text = list[i, 0];
                            richTextBox6.Text = list[i, 1];
                            richTextBox7.Text = list[i, 2];
                            richTextBox8.Text = list[i, 3];
                            richTextBox9.Text = list[i, 4];
                            richTextBox10.Text = list[i, 5];

                            list[i, 0] = "";
                            list[i, 1] = "";
                            list[i, 2] = "";
                            list[i, 3] = "";
                            list[i, 4] = "";
                            list[i, 5] = "";

                        else if ((list[i, 0] == null) || (list[i, 1] == null) || (list[i, 0] == "") || (list[i, 1] == ""))

                            list[i, 0] = name;
                            list[i, 1] = rank;
                            list[i, 2] = richTextBox7.Text;
                            list[i, 3] = richTextBox8.Text;
                            list[i, 4] = richTextBox9.Text;
                            list[i, 5] = richTextBox10.Text;

This worked fine and is also able to retrive the data and display it in the text boxes but was not able to remember the changes.

I know this a bit in efficient coding which causes so many problems.

Is there any easy way to solve the problem?


There is a rowhandle for gridview,
you will get the rowhandle for each click, get the data for that row, use grid.Row[][].tostring to store each column name in the storage variable.
Sorry, i didnt have much time to give u the exact code, pls have a check at this.

This article has been dead for over six months. Start a new discussion instead.