When I modify DataGridView, It gives system.invalidoperationexception cross-thread operation not valid?
I have a database which is SQLite and I have a windows form application. There is a DataGridView in that form which have got 4 columns. I have use a timer to update my DataGridView contents.
But Every time I clear the DataGridView and then I fill it because I have to sort them by date. If I don't use .Rows.Clear() and .Refresh it adds the same content over and over again. So I use them.
I use different way like comment lines, but problem is
system.invalidoperationexception cross-thread operation not valid
I have tried all solution of StackOverflow and whole internet, but all the way gives my same exception.
What is my problem. I have called this method directly and I have called it as a thread, It gave me same exception. It gives me exception when I use DataGridView. For example, in this code block, it gives in dgwIslemGemisi.DataSource=dt;
private void guncellemeIslemGecmisiGoster()
dt = db.TumGuncellemeIslemGecmisiGetir();
dgwIslemGecmisi.DataSource = dt;
dgwIslemGecmisi.Update();
dgwIslemGecmisi.Rows.Clear();
dgwIslemGecmisi.Refresh();
////Set AutoGenerateColumns False
//dgwIslemGecmisi.AutoGenerateColumns = false;
////Set Columns Count
//dgwIslemGecmisi.ColumnCount = 4;
////Add Columns
//dgwIslemGecmisi.Columns[0].Name = "islemAdi";
//dgwIslemGecmisi.Columns[0].HeaderText = "İşlem Adı";
//dgwIslemGecmisi.Columns[0].DataPropertyName = "islemAdi";
//dgwIslemGecmisi.Columns[1].HeaderText = "İşleme Başlangıç Tarihi";
//dgwIslemGecmisi.Columns[1].Name = "islemBaslangicTarihi";
//dgwIslemGecmisi.Columns[1].DataPropertyName = "islemBaslangicTarihi";
//dgwIslemGecmisi.Columns[2].Name = "islemBitisTarihi";
//dgwIslemGecmisi.Columns[2].HeaderText = "İşlemin Tamamlanma Tarihi";
//dgwIslemGecmisi.Columns[2].DataPropertyName = "isleminBitisTarihi";
//dgwIslemGecmisi.Columns[3].Name = "islemDurumu";
//dgwIslemGecmisi.Columns[3].HeaderText = "İşlem Durumu";
//dgwIslemGecmisi.Columns[3].DataPropertyName = "islemDurumu";
//dgwIslemGecmisi.DataSource = dt;
//for (int i = 0; i < dt.Rows.Count; i++)
//
// string durum = "Başarısız";
// if (dt.Rows[i]["islemDurumu"].ToString() == "1")
//
// durum = "Başarılı";
//
// dgwIslemGecmisi.Rows.Add(new object
// dt.Rows[i]["islemAdi"].ToString(),
// dt.Rows[i]["islemBaslangicTarihi"].ToString(),
// dt.Rows[i]["islemBitisTarihi"].ToString(),
// durum
// );
//
dt.Dispose();
c# winforms datagridview
add a comment |
I have a database which is SQLite and I have a windows form application. There is a DataGridView in that form which have got 4 columns. I have use a timer to update my DataGridView contents.
But Every time I clear the DataGridView and then I fill it because I have to sort them by date. If I don't use .Rows.Clear() and .Refresh it adds the same content over and over again. So I use them.
I use different way like comment lines, but problem is
system.invalidoperationexception cross-thread operation not valid
I have tried all solution of StackOverflow and whole internet, but all the way gives my same exception.
What is my problem. I have called this method directly and I have called it as a thread, It gave me same exception. It gives me exception when I use DataGridView. For example, in this code block, it gives in dgwIslemGemisi.DataSource=dt;
private void guncellemeIslemGecmisiGoster()
dt = db.TumGuncellemeIslemGecmisiGetir();
dgwIslemGecmisi.DataSource = dt;
dgwIslemGecmisi.Update();
dgwIslemGecmisi.Rows.Clear();
dgwIslemGecmisi.Refresh();
////Set AutoGenerateColumns False
//dgwIslemGecmisi.AutoGenerateColumns = false;
////Set Columns Count
//dgwIslemGecmisi.ColumnCount = 4;
////Add Columns
//dgwIslemGecmisi.Columns[0].Name = "islemAdi";
//dgwIslemGecmisi.Columns[0].HeaderText = "İşlem Adı";
//dgwIslemGecmisi.Columns[0].DataPropertyName = "islemAdi";
//dgwIslemGecmisi.Columns[1].HeaderText = "İşleme Başlangıç Tarihi";
//dgwIslemGecmisi.Columns[1].Name = "islemBaslangicTarihi";
//dgwIslemGecmisi.Columns[1].DataPropertyName = "islemBaslangicTarihi";
//dgwIslemGecmisi.Columns[2].Name = "islemBitisTarihi";
//dgwIslemGecmisi.Columns[2].HeaderText = "İşlemin Tamamlanma Tarihi";
//dgwIslemGecmisi.Columns[2].DataPropertyName = "isleminBitisTarihi";
//dgwIslemGecmisi.Columns[3].Name = "islemDurumu";
//dgwIslemGecmisi.Columns[3].HeaderText = "İşlem Durumu";
//dgwIslemGecmisi.Columns[3].DataPropertyName = "islemDurumu";
//dgwIslemGecmisi.DataSource = dt;
//for (int i = 0; i < dt.Rows.Count; i++)
//
// string durum = "Başarısız";
// if (dt.Rows[i]["islemDurumu"].ToString() == "1")
//
// durum = "Başarılı";
//
// dgwIslemGecmisi.Rows.Add(new object
// dt.Rows[i]["islemAdi"].ToString(),
// dt.Rows[i]["islemBaslangicTarihi"].ToString(),
// dt.Rows[i]["islemBitisTarihi"].ToString(),
// durum
// );
//
dt.Dispose();
c# winforms datagridview
You must be calling thisguncellemeIslemGecmisiGoster()in a background thread. If you fill theDataTablein a background thread you need to either wait for the thread to exit and then set theDataSourceor callInvokewhile in the background thread.
– Handbag Crab
Nov 12 at 10:24
I have call Inove like belove code block. There is no exception or error. If there is any logic or programmatic problem. You can write. Thank you so much.
– setniparis
Nov 12 at 10:33
add a comment |
I have a database which is SQLite and I have a windows form application. There is a DataGridView in that form which have got 4 columns. I have use a timer to update my DataGridView contents.
But Every time I clear the DataGridView and then I fill it because I have to sort them by date. If I don't use .Rows.Clear() and .Refresh it adds the same content over and over again. So I use them.
I use different way like comment lines, but problem is
system.invalidoperationexception cross-thread operation not valid
I have tried all solution of StackOverflow and whole internet, but all the way gives my same exception.
What is my problem. I have called this method directly and I have called it as a thread, It gave me same exception. It gives me exception when I use DataGridView. For example, in this code block, it gives in dgwIslemGemisi.DataSource=dt;
private void guncellemeIslemGecmisiGoster()
dt = db.TumGuncellemeIslemGecmisiGetir();
dgwIslemGecmisi.DataSource = dt;
dgwIslemGecmisi.Update();
dgwIslemGecmisi.Rows.Clear();
dgwIslemGecmisi.Refresh();
////Set AutoGenerateColumns False
//dgwIslemGecmisi.AutoGenerateColumns = false;
////Set Columns Count
//dgwIslemGecmisi.ColumnCount = 4;
////Add Columns
//dgwIslemGecmisi.Columns[0].Name = "islemAdi";
//dgwIslemGecmisi.Columns[0].HeaderText = "İşlem Adı";
//dgwIslemGecmisi.Columns[0].DataPropertyName = "islemAdi";
//dgwIslemGecmisi.Columns[1].HeaderText = "İşleme Başlangıç Tarihi";
//dgwIslemGecmisi.Columns[1].Name = "islemBaslangicTarihi";
//dgwIslemGecmisi.Columns[1].DataPropertyName = "islemBaslangicTarihi";
//dgwIslemGecmisi.Columns[2].Name = "islemBitisTarihi";
//dgwIslemGecmisi.Columns[2].HeaderText = "İşlemin Tamamlanma Tarihi";
//dgwIslemGecmisi.Columns[2].DataPropertyName = "isleminBitisTarihi";
//dgwIslemGecmisi.Columns[3].Name = "islemDurumu";
//dgwIslemGecmisi.Columns[3].HeaderText = "İşlem Durumu";
//dgwIslemGecmisi.Columns[3].DataPropertyName = "islemDurumu";
//dgwIslemGecmisi.DataSource = dt;
//for (int i = 0; i < dt.Rows.Count; i++)
//
// string durum = "Başarısız";
// if (dt.Rows[i]["islemDurumu"].ToString() == "1")
//
// durum = "Başarılı";
//
// dgwIslemGecmisi.Rows.Add(new object
// dt.Rows[i]["islemAdi"].ToString(),
// dt.Rows[i]["islemBaslangicTarihi"].ToString(),
// dt.Rows[i]["islemBitisTarihi"].ToString(),
// durum
// );
//
dt.Dispose();
c# winforms datagridview
I have a database which is SQLite and I have a windows form application. There is a DataGridView in that form which have got 4 columns. I have use a timer to update my DataGridView contents.
But Every time I clear the DataGridView and then I fill it because I have to sort them by date. If I don't use .Rows.Clear() and .Refresh it adds the same content over and over again. So I use them.
I use different way like comment lines, but problem is
system.invalidoperationexception cross-thread operation not valid
I have tried all solution of StackOverflow and whole internet, but all the way gives my same exception.
What is my problem. I have called this method directly and I have called it as a thread, It gave me same exception. It gives me exception when I use DataGridView. For example, in this code block, it gives in dgwIslemGemisi.DataSource=dt;
private void guncellemeIslemGecmisiGoster()
dt = db.TumGuncellemeIslemGecmisiGetir();
dgwIslemGecmisi.DataSource = dt;
dgwIslemGecmisi.Update();
dgwIslemGecmisi.Rows.Clear();
dgwIslemGecmisi.Refresh();
////Set AutoGenerateColumns False
//dgwIslemGecmisi.AutoGenerateColumns = false;
////Set Columns Count
//dgwIslemGecmisi.ColumnCount = 4;
////Add Columns
//dgwIslemGecmisi.Columns[0].Name = "islemAdi";
//dgwIslemGecmisi.Columns[0].HeaderText = "İşlem Adı";
//dgwIslemGecmisi.Columns[0].DataPropertyName = "islemAdi";
//dgwIslemGecmisi.Columns[1].HeaderText = "İşleme Başlangıç Tarihi";
//dgwIslemGecmisi.Columns[1].Name = "islemBaslangicTarihi";
//dgwIslemGecmisi.Columns[1].DataPropertyName = "islemBaslangicTarihi";
//dgwIslemGecmisi.Columns[2].Name = "islemBitisTarihi";
//dgwIslemGecmisi.Columns[2].HeaderText = "İşlemin Tamamlanma Tarihi";
//dgwIslemGecmisi.Columns[2].DataPropertyName = "isleminBitisTarihi";
//dgwIslemGecmisi.Columns[3].Name = "islemDurumu";
//dgwIslemGecmisi.Columns[3].HeaderText = "İşlem Durumu";
//dgwIslemGecmisi.Columns[3].DataPropertyName = "islemDurumu";
//dgwIslemGecmisi.DataSource = dt;
//for (int i = 0; i < dt.Rows.Count; i++)
//
// string durum = "Başarısız";
// if (dt.Rows[i]["islemDurumu"].ToString() == "1")
//
// durum = "Başarılı";
//
// dgwIslemGecmisi.Rows.Add(new object
// dt.Rows[i]["islemAdi"].ToString(),
// dt.Rows[i]["islemBaslangicTarihi"].ToString(),
// dt.Rows[i]["islemBitisTarihi"].ToString(),
// durum
// );
//
dt.Dispose();
c# winforms datagridview
c# winforms datagridview
edited Nov 12 at 10:57
Vladimir Vagaytsev
2,16592327
2,16592327
asked Nov 12 at 10:04
setniparis
12
12
You must be calling thisguncellemeIslemGecmisiGoster()in a background thread. If you fill theDataTablein a background thread you need to either wait for the thread to exit and then set theDataSourceor callInvokewhile in the background thread.
– Handbag Crab
Nov 12 at 10:24
I have call Inove like belove code block. There is no exception or error. If there is any logic or programmatic problem. You can write. Thank you so much.
– setniparis
Nov 12 at 10:33
add a comment |
You must be calling thisguncellemeIslemGecmisiGoster()in a background thread. If you fill theDataTablein a background thread you need to either wait for the thread to exit and then set theDataSourceor callInvokewhile in the background thread.
– Handbag Crab
Nov 12 at 10:24
I have call Inove like belove code block. There is no exception or error. If there is any logic or programmatic problem. You can write. Thank you so much.
– setniparis
Nov 12 at 10:33
You must be calling this
guncellemeIslemGecmisiGoster() in a background thread. If you fill the DataTable in a background thread you need to either wait for the thread to exit and then set the DataSource or call Invoke while in the background thread.– Handbag Crab
Nov 12 at 10:24
You must be calling this
guncellemeIslemGecmisiGoster() in a background thread. If you fill the DataTable in a background thread you need to either wait for the thread to exit and then set the DataSource or call Invoke while in the background thread.– Handbag Crab
Nov 12 at 10:24
I have call Inove like belove code block. There is no exception or error. If there is any logic or programmatic problem. You can write. Thank you so much.
– setniparis
Nov 12 at 10:33
I have call Inove like belove code block. There is no exception or error. If there is any logic or programmatic problem. You can write. Thank you so much.
– setniparis
Nov 12 at 10:33
add a comment |
1 Answer
1
active
oldest
votes
This is solution of exception.
private void guncellemeIslemGecmisiGoster()
dt = db.TumGuncellemeIslemGecmisiGetir();
dgwIslemGecmisi.Invoke(new Action(() => dgwIslemGecmisi.DataSource = dt));
dgwIslemGecmisi.Invoke(new Action(() => dgwIslemGecmisi.Update()));
dt.Dispose();
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53259823%2fwhen-i-modify-datagridview-it-gives-system-invalidoperationexception-cross-thre%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is solution of exception.
private void guncellemeIslemGecmisiGoster()
dt = db.TumGuncellemeIslemGecmisiGetir();
dgwIslemGecmisi.Invoke(new Action(() => dgwIslemGecmisi.DataSource = dt));
dgwIslemGecmisi.Invoke(new Action(() => dgwIslemGecmisi.Update()));
dt.Dispose();
add a comment |
This is solution of exception.
private void guncellemeIslemGecmisiGoster()
dt = db.TumGuncellemeIslemGecmisiGetir();
dgwIslemGecmisi.Invoke(new Action(() => dgwIslemGecmisi.DataSource = dt));
dgwIslemGecmisi.Invoke(new Action(() => dgwIslemGecmisi.Update()));
dt.Dispose();
add a comment |
This is solution of exception.
private void guncellemeIslemGecmisiGoster()
dt = db.TumGuncellemeIslemGecmisiGetir();
dgwIslemGecmisi.Invoke(new Action(() => dgwIslemGecmisi.DataSource = dt));
dgwIslemGecmisi.Invoke(new Action(() => dgwIslemGecmisi.Update()));
dt.Dispose();
This is solution of exception.
private void guncellemeIslemGecmisiGoster()
dt = db.TumGuncellemeIslemGecmisiGetir();
dgwIslemGecmisi.Invoke(new Action(() => dgwIslemGecmisi.DataSource = dt));
dgwIslemGecmisi.Invoke(new Action(() => dgwIslemGecmisi.Update()));
dt.Dispose();
answered Nov 12 at 10:36
setniparis
12
12
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53259823%2fwhen-i-modify-datagridview-it-gives-system-invalidoperationexception-cross-thre%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You must be calling this
guncellemeIslemGecmisiGoster()in a background thread. If you fill theDataTablein a background thread you need to either wait for the thread to exit and then set theDataSourceor callInvokewhile in the background thread.– Handbag Crab
Nov 12 at 10:24
I have call Inove like belove code block. There is no exception or error. If there is any logic or programmatic problem. You can write. Thank you so much.
– setniparis
Nov 12 at 10:33