Selected (CurrentCell) doesn´t update after i rebind a dataset to my datagrid?

R

Robert Pettersson

Hi,

I have a datagrid that I load some data into through a dataset.

Then I have som other controles, textboxes, where I can enter new posts into
my result, database.

When I have enterd a new post, I want to reload the data in the datagrid and
select the added post. Everything works fine exept the text that is kind of
selected. It´s not really selected beacuse i progamatically select another
row, that get blue. This cell is grey and the text in it is not updated
untill I click another cell. So if I scroll up and down in my datagrid the
previous cell that was selected before thae update of the datagrid is still
semiselected and "replaces" the data of the other cells as long as it is on
top of them.

Hope that you understand my problem.

This is some of my code that I use to update and reload my datagrid:

//Reload the data into the datagrid
dataGridDiscountHolders.DataSource = null;
dataGridDiscountHolders.DataBindings.Clear();

DataSet mDiscountHolders = new DataSet("DiscountHolders");
mDiscountHolders = SQLGetData.getDiscountHolders(); //This method returns
my dataset
mDiscountHolders.Tables[0].TableName = "DiscountHolders";
dataGridDiscountHolders.DataSource = mDiscountHolders.Tables[0];

//Set my newly added row to selected, var newlyAddedRow contains that id,
this part works fine.
for(int i = 0; i <
((DataTable)dataGridDiscountHolders.DataSource).Rows.Count; i++)
{
if(Convert.ToInt32(((DataTable)dataGridDiscountHolders.DataSource).Rows[0].ToString())== newlyAddedRow) { dataGridDiscountHolders.Select(i); dataGridDiscountHolders.CurrentRowIndex = i; } else dataGridDiscountHolders.UnSelect(i);}dataGridDiscountHolders.Update();dataGridDiscountHolders.Refresh();If anyone could give me some tips to remove the previous selected text, Iwould be very greateful!/Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top