Datagrid ghost selection
-
I have a datagrid that I populate by:
OleDbConnection dbConnection = new OleDbConnection(); OleDbCommand tableCommand = null; OleDbDataReader reader = null; dbConnection.ConnectionString = sConnString; dbConnection.Open(); tableCommand = dbConnection.CreateCommand(); tableCommand.CommandText = sSQL; DataSet ds = new DataSet(); OracleDataAdapter adapter = new OracleDataAdapter(); adapter.SelectCommand = tableCommand; adapter.Fill(ds, "AllPatients"); dataGridPatients.SetDataBinding(ds, "AllPatients");
This works fine. I alter sSQL based on selections made on a Windows form. However, when I execute this code a second (or third) time, the selected Datagrid cell retains its original value until I select the cell again. Assuming the current datagrid row is: 1|Bob|Jones| and Jones is selected, loading a dataset that contains 3|John|Smith| results in 1|John|Jones| being displayed. However, as soon as I select (manually) the Jones cell, Smith displays. If I have several rows displayed origianally, and select a cell in a row greater than the number of rows displayed the next time, that cell remains in the datagrid. What do I have to do to get the previously selected cell from retaining its selection? I have tried to unselect the row, to set current cell to something else, and to simulate a mousedown on the selected cell (which fires, but doesn't actually change the current visual cues). Thanks, Glenn