How to clear datagridview in c# for displaying another file?How do I calculate someone's age in C#?How do you give a C# Auto-Property a default value?How do I enumerate an enum in C#?How to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?How do I update the GUI from another thread?How to loop through all enum values in C#?VB.NET: Clear DataGridViewHow clear panel and datagridview After Postback?How to display different records on text fields from different tables with only 1 dataGridView?

administrative duties kill the research spirit?

Did Snape really give Umbridge a fake Veritaserum potion that Harry later pretended to drink?

Using Sed to add counter to keyword

Bypass with wrong cvv of debit card and getting OTP

What does the ash content of broken wheat really mean?

How do both sides know the MTU

What instances can be solved today by modern solvers (pure LP)?

Why would "dead languages" be the only languages that spells could be written in?

Did Stalin kill all Soviet officers involved in the Winter War?

Do the 26 richest billionaires own as much wealth as the poorest 3.8 billion people?

How to improve the size of cells in this table?

How can one synthesise a conjugated alkyne chain?

Olive oil in Japanese cooking

Has there ever been a cold war other than between the U.S. and the U.S.S.R.?

Phrasing "it says" or "it reads"

How to respond to someone who condemns behavior similar to what they exhibit?

What is meant by perfect, imperfect consonance and dissonance?

Was Wolfgang Unzicker the last Amateur GM?

Isn't "Dave's protocol" good if only the database, and not the code, is leaked?

Has chattel slavery ever been used as a criminal punishment in the USA since the passage of the Thirteenth Amendment?

What are the differences of checking a self-signed certificate vs ignore it?

What is the difference between a historical drama and a period drama?

Machine Learning Golf: Multiplication

Simple OOP currency converter



How to clear datagridview in c# for displaying another file?


How do I calculate someone's age in C#?How do you give a C# Auto-Property a default value?How do I enumerate an enum in C#?How to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?How do I update the GUI from another thread?How to loop through all enum values in C#?VB.NET: Clear DataGridViewHow clear panel and datagridview After Postback?How to display different records on text fields from different tables with only 1 dataGridView?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am building an application in which i'm displaying an excel file in datagridview. I've given display button for showing data. My problem is once I click button, it works fine but after my second attempt it appends data with previous data. I want to clear datagridview for displaying new data again.
So, what code should I implement?



I tried dataGridView1.DataSource = null; and dataGridView1.Rows.Clear();, but they didn't work for my need










share|improve this question
























  • Been a bit since I used these, but I believe that during initial setup you had to use dataGridView1.DataSource = X, have you attempted to clear the X object?

    – dmoore1181
    Mar 25 at 18:47






  • 1





    setting the data source to null should work so there must be a flaw in your logic elsewhere. Please post more code.

    – eddyizm
    Mar 25 at 18:50











  • Setting DataSource = null should work. Sounds like you are appending data to the data source object instead of clearing/overriding the old data.

    – OhBeWise
    Mar 25 at 20:42

















0















I am building an application in which i'm displaying an excel file in datagridview. I've given display button for showing data. My problem is once I click button, it works fine but after my second attempt it appends data with previous data. I want to clear datagridview for displaying new data again.
So, what code should I implement?



I tried dataGridView1.DataSource = null; and dataGridView1.Rows.Clear();, but they didn't work for my need










share|improve this question
























  • Been a bit since I used these, but I believe that during initial setup you had to use dataGridView1.DataSource = X, have you attempted to clear the X object?

    – dmoore1181
    Mar 25 at 18:47






  • 1





    setting the data source to null should work so there must be a flaw in your logic elsewhere. Please post more code.

    – eddyizm
    Mar 25 at 18:50











  • Setting DataSource = null should work. Sounds like you are appending data to the data source object instead of clearing/overriding the old data.

    – OhBeWise
    Mar 25 at 20:42













0












0








0








I am building an application in which i'm displaying an excel file in datagridview. I've given display button for showing data. My problem is once I click button, it works fine but after my second attempt it appends data with previous data. I want to clear datagridview for displaying new data again.
So, what code should I implement?



I tried dataGridView1.DataSource = null; and dataGridView1.Rows.Clear();, but they didn't work for my need










share|improve this question
















I am building an application in which i'm displaying an excel file in datagridview. I've given display button for showing data. My problem is once I click button, it works fine but after my second attempt it appends data with previous data. I want to clear datagridview for displaying new data again.
So, what code should I implement?



I tried dataGridView1.DataSource = null; and dataGridView1.Rows.Clear();, but they didn't work for my need







c# excel datagridview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 18:47









João Fernandes

3583 silver badges12 bronze badges




3583 silver badges12 bronze badges










asked Mar 25 at 18:42









rutu chavanrutu chavan

12 bronze badges




12 bronze badges












  • Been a bit since I used these, but I believe that during initial setup you had to use dataGridView1.DataSource = X, have you attempted to clear the X object?

    – dmoore1181
    Mar 25 at 18:47






  • 1





    setting the data source to null should work so there must be a flaw in your logic elsewhere. Please post more code.

    – eddyizm
    Mar 25 at 18:50











  • Setting DataSource = null should work. Sounds like you are appending data to the data source object instead of clearing/overriding the old data.

    – OhBeWise
    Mar 25 at 20:42

















  • Been a bit since I used these, but I believe that during initial setup you had to use dataGridView1.DataSource = X, have you attempted to clear the X object?

    – dmoore1181
    Mar 25 at 18:47






  • 1





    setting the data source to null should work so there must be a flaw in your logic elsewhere. Please post more code.

    – eddyizm
    Mar 25 at 18:50











  • Setting DataSource = null should work. Sounds like you are appending data to the data source object instead of clearing/overriding the old data.

    – OhBeWise
    Mar 25 at 20:42
















Been a bit since I used these, but I believe that during initial setup you had to use dataGridView1.DataSource = X, have you attempted to clear the X object?

– dmoore1181
Mar 25 at 18:47





Been a bit since I used these, but I believe that during initial setup you had to use dataGridView1.DataSource = X, have you attempted to clear the X object?

– dmoore1181
Mar 25 at 18:47




1




1





setting the data source to null should work so there must be a flaw in your logic elsewhere. Please post more code.

– eddyizm
Mar 25 at 18:50





setting the data source to null should work so there must be a flaw in your logic elsewhere. Please post more code.

– eddyizm
Mar 25 at 18:50













Setting DataSource = null should work. Sounds like you are appending data to the data source object instead of clearing/overriding the old data.

– OhBeWise
Mar 25 at 20:42





Setting DataSource = null should work. Sounds like you are appending data to the data source object instead of clearing/overriding the old data.

– OhBeWise
Mar 25 at 20:42












0






active

oldest

votes










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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55344516%2fhow-to-clear-datagridview-in-c-sharp-for-displaying-another-file%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55344516%2fhow-to-clear-datagridview-in-c-sharp-for-displaying-another-file%23new-answer', 'question_page');

);

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







Popular posts from this blog

Obelisk of Theodosius Contents History Description Notes Bibliography Further reading External links Navigation menuAge of spirituality : late antique and early Christian art, third to seventh centuryOver 60 picturesObelisks of the World41°00′21.24″N 28°58′31.43″E / 41.0059000°N 28.9753972°E / 41.0059000; 28.97539727724550-7235741376235741376

밀양 대씨 역사 각주 함께 보기 둘러보기 메뉴밀양 대씨

1973년 목차 사건 문화 탄생 사망 노벨상 달력 둘러보기 메뉴