-
May 15th, 2023, 12:41 PM
#1
Thread Starter
Junior Member
Why my DataGridView shimmers (column shrink and resume their sizes)
Hi all,
I have a Datagridview that receives external data and I added 3 columns independent of the external data
My datagridview refreshes every 3 seconds and during refreshment the table sparkles (i.e. the cells shrink and return to their original sizes) and also the content of the 3 independent columns (those added) disappears and reappears.
I have this problem with this code addition (see below which corresponds to an added colone), if I remove this piece of code the problem disappears:
Code:
var id = row.Cells[0].Value.ToString();
var nickNameTask = Task.Run<string>(async() => await this.GetTraderName(id));
nickNameTask.Wait();
string nickName = nickNameTask.Result;
row.Cells[1].Value =nickName;
Do you know where the problem may come from and how to fix it?
Here is the code:
Code:
private void dtgvPositions_DataBindingComplete(
object sender,
DataGridViewBindingCompleteEventArgs e)
{
List<string> lstUID = this.ReplaceDownTheLine(this.txtUIDs.Text.Trim());
Dictionary<string, bool> lstUIDColor = new Dictionary<string, bool>();
for (int index = 0; index < lstUID.Count; ++index)
lstUIDColor.Add(lstUID[index], index % 2 == 0);
this.dtgvPositions.Invoke((Action)(() =>
{
foreach (string str in lstUID)
{
foreach (DataGridViewRow row in (IEnumerable)this.dtgvPositions.Rows)
{
string key = row.Cells[0].Value.ToString();
Decimal num = 0M;
Decimal num1 = 0M;
Decimal num2 = 0M;
Decimal num3 = 0M;
try
{
num = Decimal.Parse(row.Cells[9].Value.ToString());
num1 = Decimal.Parse(row.Cells[5].Value.ToString());
num2 = Decimal.Parse(row.Cells[7].Value.ToString());
num3 = Decimal.Parse(row.Cells[3].Value.ToString());
var id = row.Cells[0].Value.ToString();
var nickNameTask = Task.Run<string>(async() => await this.GetTraderName(id));
nickNameTask.Wait();
string nickName = nickNameTask.Result;
row.Cells[1].Value =nickName;
bool flag;
lstUIDColor.TryGetValue(key, out flag);
row.DefaultCellStyle.BackColor = Color.FromArgb(24, 26, 32);
row.Cells[1].Selected = false;
row.Cells[1].Style.ForeColor = flag ? Color.LightSkyBlue : Color.LightPink;
row.Cells[2].Value = num1 >= 0M ? "Long" : "Short";
row.Cells[2].Style.ForeColor = num1 >= 0M ? Color.FromArgb(22, 181, 93) : Color.FromArgb(194, 52, 54);
row.Cells[6].Value = (num1 * num2) / num3;
row.Cells[9].Style.ForeColor = num >= 0M ? Color.FromArgb(22, 181, 93) : Color.FromArgb(194, 52, 54);
row.Cells[10].Style.ForeColor = num >= 0M ? Color.FromArgb(22, 181, 93) : Color.FromArgb(194, 52, 54);
}
catch
{
}
}
}
}));
}
Last edited by jmcilhinney; May 15th, 2023 at 08:52 PM.
Reason: Translated to English
-
May 15th, 2023, 08:53 PM
#2
Re: Why my DataGridView shimmers (column shrink and resume their sizes)
Your thread title and post have been translated to English. We only accept posts in English on this site. Any further threads not in English will be closed.
-
May 15th, 2023, 10:24 PM
#3
Thread Starter
Junior Member
Re: Why my DataGridView shimmers (column shrink and resume their sizes)
-
May 15th, 2023, 11:26 PM
#4
Re: Why my DataGridView shimmers (column shrink and resume their sizes)
The problem is that your event handler is executed on the UI thread and you're freezing that thread every time you call Wait. You'd be better off getting all the data you need first, initiating a thread or task to do that work and marshalling back to the UI thread as required along the way or once at the end. That way, you only monopolise the UI thread to make changes to the UI, not to do a lot of background work. I'd have to look more closely at the code to provide more specific advice and I don;t have time for that right now, but that's the way you need to go.
-
Sep 6th, 2023, 04:25 AM
#5
Thread Starter
Junior Member
Re: Why my DataGridView shimmers (column shrink and resume their sizes)
 Originally Posted by jmcilhinney
The problem is that your event handler is executed on the UI thread and you're freezing that thread every time you call Wait. You'd be better off getting all the data you need first, initiating a thread or task to do that work and marshalling back to the UI thread as required along the way or once at the end. That way, you only monopolise the UI thread to make changes to the UI, not to do a lot of background work. I'd have to look more closely at the code to provide more specific advice and I don;t have time for that right now, but that's the way you need to go.
Hi, there,
Really sorry for the long delay as I had a problem with my PC
My problem is still there, what's a thread?
Do you know how to get all the data first?
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|