Posted on 2004-09-28
hello. I have found understanding how the VB.NET c# datagrids are supposed to be used to be hard work.
But they are obviously powerful. I have 2 questions.
1) (EASY) Can you tell me how to disable the "edittable" nature of the datagrid and set it so that if a cell is double clicked it doesn't activate it (for want of a beter word) for editting? i am using a mySql Datbase and I maually read with sql into a query and I don't want to have the illusion the datagrid can be editted - it can't - to do that you have to double click a row to get a edit box.
here is the difficult bit... I want to loop through the datagrid and check if the row is selected and collect the "id" column value into an array. the grid works great and the below code works fine UNTIL the user decides to alter the datagrid order (say to "ASCending on date") by clicking on the column header.
What does this do? well the by clicking to resort the data only the data posted to the screen gets physically resorted, the following code gets all messed up - it WRONGLY IGNORES the new order and continually posts OLD column values. A reordered datagrid should show the data of the new order. But it doesn't ( so its effecivley gibberish to re-order it) i.e. the new order the user generated has not been adopted by the datagrid really - the "selected rows" still pertain to the original sort order only.
private void button1_Click(object sender, System.EventArgs e)
MessageBox.Show("row:" + Contacts.Rows[i]["id"] + "");
obviously I am diong something wrong. Either I need to "refresh" the datatable/datagrid so it realises its been reordered by the user or I have to have a better piece of code than the "BODGE JOB" I have written above. I am obviously NOT doing this right.. can you help..?