Drag and Drop Rows of Datagrid View Winform C#











up vote
0
down vote

favorite
1












I want to Drag Rows from certain position to another position in same grid view. The Other rows should automatically adjust according to the Drag and Drop.



Thank You










share|improve this question


















  • 2




    What have you tried so far? Remember, Stack Overflow is not a place, where people write code for you! Please read.
    – R. Gadeev
    May 10 '17 at 11:02










  • tried dragdrop event but not working for me
    – Ravi
    May 10 '17 at 11:08






  • 2




    please also post the code to show what you have tried. That makes the life of the people easier who are willing to help you.
    – Mong Zhu
    May 10 '17 at 11:10















up vote
0
down vote

favorite
1












I want to Drag Rows from certain position to another position in same grid view. The Other rows should automatically adjust according to the Drag and Drop.



Thank You










share|improve this question


















  • 2




    What have you tried so far? Remember, Stack Overflow is not a place, where people write code for you! Please read.
    – R. Gadeev
    May 10 '17 at 11:02










  • tried dragdrop event but not working for me
    – Ravi
    May 10 '17 at 11:08






  • 2




    please also post the code to show what you have tried. That makes the life of the people easier who are willing to help you.
    – Mong Zhu
    May 10 '17 at 11:10













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





I want to Drag Rows from certain position to another position in same grid view. The Other rows should automatically adjust according to the Drag and Drop.



Thank You










share|improve this question













I want to Drag Rows from certain position to another position in same grid view. The Other rows should automatically adjust according to the Drag and Drop.



Thank You







c# datagridview






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 10 '17 at 10:57









Ravi

932213




932213








  • 2




    What have you tried so far? Remember, Stack Overflow is not a place, where people write code for you! Please read.
    – R. Gadeev
    May 10 '17 at 11:02










  • tried dragdrop event but not working for me
    – Ravi
    May 10 '17 at 11:08






  • 2




    please also post the code to show what you have tried. That makes the life of the people easier who are willing to help you.
    – Mong Zhu
    May 10 '17 at 11:10














  • 2




    What have you tried so far? Remember, Stack Overflow is not a place, where people write code for you! Please read.
    – R. Gadeev
    May 10 '17 at 11:02










  • tried dragdrop event but not working for me
    – Ravi
    May 10 '17 at 11:08






  • 2




    please also post the code to show what you have tried. That makes the life of the people easier who are willing to help you.
    – Mong Zhu
    May 10 '17 at 11:10








2




2




What have you tried so far? Remember, Stack Overflow is not a place, where people write code for you! Please read.
– R. Gadeev
May 10 '17 at 11:02




What have you tried so far? Remember, Stack Overflow is not a place, where people write code for you! Please read.
– R. Gadeev
May 10 '17 at 11:02












tried dragdrop event but not working for me
– Ravi
May 10 '17 at 11:08




tried dragdrop event but not working for me
– Ravi
May 10 '17 at 11:08




2




2




please also post the code to show what you have tried. That makes the life of the people easier who are willing to help you.
– Mong Zhu
May 10 '17 at 11:10




please also post the code to show what you have tried. That makes the life of the people easier who are willing to help you.
– Mong Zhu
May 10 '17 at 11:10












1 Answer
1






active

oldest

votes

















up vote
7
down vote



accepted










I much prefer using mouse events over actual drag&drop events for this when doing d&d within an application.



1 - Unbound example



Here is a simple example that uses the mouse events to drag rows around while diplaying one Cell value in a Label.



It inserts the row after the one you drop it on.



The dragLabel part is optional..



enter image description here



First we declare two helper variables at class level:



int dragRow = -1;
Label dragLabel = null;


Then we code the CellMouseDown to prepare the Label..:



private void dataGridView1_CellMouseDown(object sender,DataGridViewCellMouseEventArgs e)
{
if (e.ColumnIndex<0 || e.RowIndex < 0) return;
dragRow = e.RowIndex;
if (dragLabel == null) dragLabel = new Label();
dragLabel.Text = dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
dragLabel.Parent = dataGridView1;
dragLabel.Location = e.Location;
}


In the MouseMove we just move the Label. But as the MouseDown usually starts a cell selection we clear the selection..



private void dataGridView1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && dragLabel != null)
{
dragLabel.Location = e.Location;
dataGridView1.ClearSelection();
}
}


The real work is in the MouseUp. We need a HitTest to find out which, if any, row we are on. We also need to calculate the target row depending on the direction of the drag.



Finally we clean up the Label..



private void dataGridView1_MouseUp(object sender, MouseEventArgs e)
{
var hit = dataGridView1.HitTest(e.X,e.Y);
int dropRow = -1;
if (hit.Type != DataGridViewHitTestType.None)
{
dropRow = hit.RowIndex;
if (dragRow >= 0 )
{
int tgtRow = dropRow + (dragRow > dropRow ? 1 : 0);
if (tgtRow != dragRow)
{
DataGridViewRow row = dataGridView1.Rows[dragRow];
dataGridView1.Rows.Remove(row);
dataGridView1.Rows.Insert(tgtRow, row);

dataGridView1.ClearSelection();
row.Selected = true;
}
}
}
else { dataGridView1.Rows[dragRow].Selected = true;}

if (dragLabel != null)
{
dragLabel.Dispose();
dragLabel = null;
}
}


A few notes:



Make sure no row is new or modified or you can't move it. It took me awhile to realize that I had to switch off AllowUserToAddRows before adding the rows initially..



The treatment of selections is up to you. I chose to select the dragged row if the drop fails. And I chose to let it fail when dragging into the empty space.



Update:



2 - DataBound example



If the DGV is data-bound you can't move the rows directly. Instead you need to move the rows in the DataSource.



Let's assume you have a DataTable DT. Then you can remove rows from it and insert rows at any position. (Quite different from SQL DBMS tables!)



Note that a DataRow loses its values once removed from the DataTable. Therefore we need to clone the values before we remove the row. Other than that the code is pretty much the same. Simply replace the innermost condition with this:



if (tgtRow != dragRow)
{
DataRow dtRow = DT.Rows[dragRow];
DataRow newRow = DT.NewRow();
newRow.ItemArray = DT.Rows[dragRow].ItemArray; // we need to clone the values

DT.Rows.Remove(dtRow);
DT.Rows.InsertAt(newRow, tgtRow);
dataGridView1.Refresh();
dataGridView1.Rows[tgtRow].Selected = true;
}





share|improve this answer























  • Getting this error "Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound."
    – Ravi
    May 10 '17 at 11:26












  • Ah, that is right. you should have mentioned that in the question. I'll modify the answer in a little while..
    – TaW
    May 10 '17 at 11:29










  • Waiting for your answer. thanks in advance.
    – Ravi
    May 10 '17 at 11:53










  • Updated the answer. Note that I didn't test the label part..
    – TaW
    May 10 '17 at 12:25










  • Working Perfectaly... thanks a lot.
    – Ravi
    May 10 '17 at 12:33











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',
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%2f43890477%2fdrag-and-drop-rows-of-datagrid-view-winform-c-sharp%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








up vote
7
down vote



accepted










I much prefer using mouse events over actual drag&drop events for this when doing d&d within an application.



1 - Unbound example



Here is a simple example that uses the mouse events to drag rows around while diplaying one Cell value in a Label.



It inserts the row after the one you drop it on.



The dragLabel part is optional..



enter image description here



First we declare two helper variables at class level:



int dragRow = -1;
Label dragLabel = null;


Then we code the CellMouseDown to prepare the Label..:



private void dataGridView1_CellMouseDown(object sender,DataGridViewCellMouseEventArgs e)
{
if (e.ColumnIndex<0 || e.RowIndex < 0) return;
dragRow = e.RowIndex;
if (dragLabel == null) dragLabel = new Label();
dragLabel.Text = dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
dragLabel.Parent = dataGridView1;
dragLabel.Location = e.Location;
}


In the MouseMove we just move the Label. But as the MouseDown usually starts a cell selection we clear the selection..



private void dataGridView1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && dragLabel != null)
{
dragLabel.Location = e.Location;
dataGridView1.ClearSelection();
}
}


The real work is in the MouseUp. We need a HitTest to find out which, if any, row we are on. We also need to calculate the target row depending on the direction of the drag.



Finally we clean up the Label..



private void dataGridView1_MouseUp(object sender, MouseEventArgs e)
{
var hit = dataGridView1.HitTest(e.X,e.Y);
int dropRow = -1;
if (hit.Type != DataGridViewHitTestType.None)
{
dropRow = hit.RowIndex;
if (dragRow >= 0 )
{
int tgtRow = dropRow + (dragRow > dropRow ? 1 : 0);
if (tgtRow != dragRow)
{
DataGridViewRow row = dataGridView1.Rows[dragRow];
dataGridView1.Rows.Remove(row);
dataGridView1.Rows.Insert(tgtRow, row);

dataGridView1.ClearSelection();
row.Selected = true;
}
}
}
else { dataGridView1.Rows[dragRow].Selected = true;}

if (dragLabel != null)
{
dragLabel.Dispose();
dragLabel = null;
}
}


A few notes:



Make sure no row is new or modified or you can't move it. It took me awhile to realize that I had to switch off AllowUserToAddRows before adding the rows initially..



The treatment of selections is up to you. I chose to select the dragged row if the drop fails. And I chose to let it fail when dragging into the empty space.



Update:



2 - DataBound example



If the DGV is data-bound you can't move the rows directly. Instead you need to move the rows in the DataSource.



Let's assume you have a DataTable DT. Then you can remove rows from it and insert rows at any position. (Quite different from SQL DBMS tables!)



Note that a DataRow loses its values once removed from the DataTable. Therefore we need to clone the values before we remove the row. Other than that the code is pretty much the same. Simply replace the innermost condition with this:



if (tgtRow != dragRow)
{
DataRow dtRow = DT.Rows[dragRow];
DataRow newRow = DT.NewRow();
newRow.ItemArray = DT.Rows[dragRow].ItemArray; // we need to clone the values

DT.Rows.Remove(dtRow);
DT.Rows.InsertAt(newRow, tgtRow);
dataGridView1.Refresh();
dataGridView1.Rows[tgtRow].Selected = true;
}





share|improve this answer























  • Getting this error "Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound."
    – Ravi
    May 10 '17 at 11:26












  • Ah, that is right. you should have mentioned that in the question. I'll modify the answer in a little while..
    – TaW
    May 10 '17 at 11:29










  • Waiting for your answer. thanks in advance.
    – Ravi
    May 10 '17 at 11:53










  • Updated the answer. Note that I didn't test the label part..
    – TaW
    May 10 '17 at 12:25










  • Working Perfectaly... thanks a lot.
    – Ravi
    May 10 '17 at 12:33















up vote
7
down vote



accepted










I much prefer using mouse events over actual drag&drop events for this when doing d&d within an application.



1 - Unbound example



Here is a simple example that uses the mouse events to drag rows around while diplaying one Cell value in a Label.



It inserts the row after the one you drop it on.



The dragLabel part is optional..



enter image description here



First we declare two helper variables at class level:



int dragRow = -1;
Label dragLabel = null;


Then we code the CellMouseDown to prepare the Label..:



private void dataGridView1_CellMouseDown(object sender,DataGridViewCellMouseEventArgs e)
{
if (e.ColumnIndex<0 || e.RowIndex < 0) return;
dragRow = e.RowIndex;
if (dragLabel == null) dragLabel = new Label();
dragLabel.Text = dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
dragLabel.Parent = dataGridView1;
dragLabel.Location = e.Location;
}


In the MouseMove we just move the Label. But as the MouseDown usually starts a cell selection we clear the selection..



private void dataGridView1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && dragLabel != null)
{
dragLabel.Location = e.Location;
dataGridView1.ClearSelection();
}
}


The real work is in the MouseUp. We need a HitTest to find out which, if any, row we are on. We also need to calculate the target row depending on the direction of the drag.



Finally we clean up the Label..



private void dataGridView1_MouseUp(object sender, MouseEventArgs e)
{
var hit = dataGridView1.HitTest(e.X,e.Y);
int dropRow = -1;
if (hit.Type != DataGridViewHitTestType.None)
{
dropRow = hit.RowIndex;
if (dragRow >= 0 )
{
int tgtRow = dropRow + (dragRow > dropRow ? 1 : 0);
if (tgtRow != dragRow)
{
DataGridViewRow row = dataGridView1.Rows[dragRow];
dataGridView1.Rows.Remove(row);
dataGridView1.Rows.Insert(tgtRow, row);

dataGridView1.ClearSelection();
row.Selected = true;
}
}
}
else { dataGridView1.Rows[dragRow].Selected = true;}

if (dragLabel != null)
{
dragLabel.Dispose();
dragLabel = null;
}
}


A few notes:



Make sure no row is new or modified or you can't move it. It took me awhile to realize that I had to switch off AllowUserToAddRows before adding the rows initially..



The treatment of selections is up to you. I chose to select the dragged row if the drop fails. And I chose to let it fail when dragging into the empty space.



Update:



2 - DataBound example



If the DGV is data-bound you can't move the rows directly. Instead you need to move the rows in the DataSource.



Let's assume you have a DataTable DT. Then you can remove rows from it and insert rows at any position. (Quite different from SQL DBMS tables!)



Note that a DataRow loses its values once removed from the DataTable. Therefore we need to clone the values before we remove the row. Other than that the code is pretty much the same. Simply replace the innermost condition with this:



if (tgtRow != dragRow)
{
DataRow dtRow = DT.Rows[dragRow];
DataRow newRow = DT.NewRow();
newRow.ItemArray = DT.Rows[dragRow].ItemArray; // we need to clone the values

DT.Rows.Remove(dtRow);
DT.Rows.InsertAt(newRow, tgtRow);
dataGridView1.Refresh();
dataGridView1.Rows[tgtRow].Selected = true;
}





share|improve this answer























  • Getting this error "Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound."
    – Ravi
    May 10 '17 at 11:26












  • Ah, that is right. you should have mentioned that in the question. I'll modify the answer in a little while..
    – TaW
    May 10 '17 at 11:29










  • Waiting for your answer. thanks in advance.
    – Ravi
    May 10 '17 at 11:53










  • Updated the answer. Note that I didn't test the label part..
    – TaW
    May 10 '17 at 12:25










  • Working Perfectaly... thanks a lot.
    – Ravi
    May 10 '17 at 12:33













up vote
7
down vote



accepted







up vote
7
down vote



accepted






I much prefer using mouse events over actual drag&drop events for this when doing d&d within an application.



1 - Unbound example



Here is a simple example that uses the mouse events to drag rows around while diplaying one Cell value in a Label.



It inserts the row after the one you drop it on.



The dragLabel part is optional..



enter image description here



First we declare two helper variables at class level:



int dragRow = -1;
Label dragLabel = null;


Then we code the CellMouseDown to prepare the Label..:



private void dataGridView1_CellMouseDown(object sender,DataGridViewCellMouseEventArgs e)
{
if (e.ColumnIndex<0 || e.RowIndex < 0) return;
dragRow = e.RowIndex;
if (dragLabel == null) dragLabel = new Label();
dragLabel.Text = dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
dragLabel.Parent = dataGridView1;
dragLabel.Location = e.Location;
}


In the MouseMove we just move the Label. But as the MouseDown usually starts a cell selection we clear the selection..



private void dataGridView1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && dragLabel != null)
{
dragLabel.Location = e.Location;
dataGridView1.ClearSelection();
}
}


The real work is in the MouseUp. We need a HitTest to find out which, if any, row we are on. We also need to calculate the target row depending on the direction of the drag.



Finally we clean up the Label..



private void dataGridView1_MouseUp(object sender, MouseEventArgs e)
{
var hit = dataGridView1.HitTest(e.X,e.Y);
int dropRow = -1;
if (hit.Type != DataGridViewHitTestType.None)
{
dropRow = hit.RowIndex;
if (dragRow >= 0 )
{
int tgtRow = dropRow + (dragRow > dropRow ? 1 : 0);
if (tgtRow != dragRow)
{
DataGridViewRow row = dataGridView1.Rows[dragRow];
dataGridView1.Rows.Remove(row);
dataGridView1.Rows.Insert(tgtRow, row);

dataGridView1.ClearSelection();
row.Selected = true;
}
}
}
else { dataGridView1.Rows[dragRow].Selected = true;}

if (dragLabel != null)
{
dragLabel.Dispose();
dragLabel = null;
}
}


A few notes:



Make sure no row is new or modified or you can't move it. It took me awhile to realize that I had to switch off AllowUserToAddRows before adding the rows initially..



The treatment of selections is up to you. I chose to select the dragged row if the drop fails. And I chose to let it fail when dragging into the empty space.



Update:



2 - DataBound example



If the DGV is data-bound you can't move the rows directly. Instead you need to move the rows in the DataSource.



Let's assume you have a DataTable DT. Then you can remove rows from it and insert rows at any position. (Quite different from SQL DBMS tables!)



Note that a DataRow loses its values once removed from the DataTable. Therefore we need to clone the values before we remove the row. Other than that the code is pretty much the same. Simply replace the innermost condition with this:



if (tgtRow != dragRow)
{
DataRow dtRow = DT.Rows[dragRow];
DataRow newRow = DT.NewRow();
newRow.ItemArray = DT.Rows[dragRow].ItemArray; // we need to clone the values

DT.Rows.Remove(dtRow);
DT.Rows.InsertAt(newRow, tgtRow);
dataGridView1.Refresh();
dataGridView1.Rows[tgtRow].Selected = true;
}





share|improve this answer














I much prefer using mouse events over actual drag&drop events for this when doing d&d within an application.



1 - Unbound example



Here is a simple example that uses the mouse events to drag rows around while diplaying one Cell value in a Label.



It inserts the row after the one you drop it on.



The dragLabel part is optional..



enter image description here



First we declare two helper variables at class level:



int dragRow = -1;
Label dragLabel = null;


Then we code the CellMouseDown to prepare the Label..:



private void dataGridView1_CellMouseDown(object sender,DataGridViewCellMouseEventArgs e)
{
if (e.ColumnIndex<0 || e.RowIndex < 0) return;
dragRow = e.RowIndex;
if (dragLabel == null) dragLabel = new Label();
dragLabel.Text = dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
dragLabel.Parent = dataGridView1;
dragLabel.Location = e.Location;
}


In the MouseMove we just move the Label. But as the MouseDown usually starts a cell selection we clear the selection..



private void dataGridView1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && dragLabel != null)
{
dragLabel.Location = e.Location;
dataGridView1.ClearSelection();
}
}


The real work is in the MouseUp. We need a HitTest to find out which, if any, row we are on. We also need to calculate the target row depending on the direction of the drag.



Finally we clean up the Label..



private void dataGridView1_MouseUp(object sender, MouseEventArgs e)
{
var hit = dataGridView1.HitTest(e.X,e.Y);
int dropRow = -1;
if (hit.Type != DataGridViewHitTestType.None)
{
dropRow = hit.RowIndex;
if (dragRow >= 0 )
{
int tgtRow = dropRow + (dragRow > dropRow ? 1 : 0);
if (tgtRow != dragRow)
{
DataGridViewRow row = dataGridView1.Rows[dragRow];
dataGridView1.Rows.Remove(row);
dataGridView1.Rows.Insert(tgtRow, row);

dataGridView1.ClearSelection();
row.Selected = true;
}
}
}
else { dataGridView1.Rows[dragRow].Selected = true;}

if (dragLabel != null)
{
dragLabel.Dispose();
dragLabel = null;
}
}


A few notes:



Make sure no row is new or modified or you can't move it. It took me awhile to realize that I had to switch off AllowUserToAddRows before adding the rows initially..



The treatment of selections is up to you. I chose to select the dragged row if the drop fails. And I chose to let it fail when dragging into the empty space.



Update:



2 - DataBound example



If the DGV is data-bound you can't move the rows directly. Instead you need to move the rows in the DataSource.



Let's assume you have a DataTable DT. Then you can remove rows from it and insert rows at any position. (Quite different from SQL DBMS tables!)



Note that a DataRow loses its values once removed from the DataTable. Therefore we need to clone the values before we remove the row. Other than that the code is pretty much the same. Simply replace the innermost condition with this:



if (tgtRow != dragRow)
{
DataRow dtRow = DT.Rows[dragRow];
DataRow newRow = DT.NewRow();
newRow.ItemArray = DT.Rows[dragRow].ItemArray; // we need to clone the values

DT.Rows.Remove(dtRow);
DT.Rows.InsertAt(newRow, tgtRow);
dataGridView1.Refresh();
dataGridView1.Rows[tgtRow].Selected = true;
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 11 at 7:21









LeoDerja

1916




1916










answered May 10 '17 at 11:14









TaW

40.4k62662




40.4k62662












  • Getting this error "Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound."
    – Ravi
    May 10 '17 at 11:26












  • Ah, that is right. you should have mentioned that in the question. I'll modify the answer in a little while..
    – TaW
    May 10 '17 at 11:29










  • Waiting for your answer. thanks in advance.
    – Ravi
    May 10 '17 at 11:53










  • Updated the answer. Note that I didn't test the label part..
    – TaW
    May 10 '17 at 12:25










  • Working Perfectaly... thanks a lot.
    – Ravi
    May 10 '17 at 12:33


















  • Getting this error "Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound."
    – Ravi
    May 10 '17 at 11:26












  • Ah, that is right. you should have mentioned that in the question. I'll modify the answer in a little while..
    – TaW
    May 10 '17 at 11:29










  • Waiting for your answer. thanks in advance.
    – Ravi
    May 10 '17 at 11:53










  • Updated the answer. Note that I didn't test the label part..
    – TaW
    May 10 '17 at 12:25










  • Working Perfectaly... thanks a lot.
    – Ravi
    May 10 '17 at 12:33
















Getting this error "Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound."
– Ravi
May 10 '17 at 11:26






Getting this error "Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound."
– Ravi
May 10 '17 at 11:26














Ah, that is right. you should have mentioned that in the question. I'll modify the answer in a little while..
– TaW
May 10 '17 at 11:29




Ah, that is right. you should have mentioned that in the question. I'll modify the answer in a little while..
– TaW
May 10 '17 at 11:29












Waiting for your answer. thanks in advance.
– Ravi
May 10 '17 at 11:53




Waiting for your answer. thanks in advance.
– Ravi
May 10 '17 at 11:53












Updated the answer. Note that I didn't test the label part..
– TaW
May 10 '17 at 12:25




Updated the answer. Note that I didn't test the label part..
– TaW
May 10 '17 at 12:25












Working Perfectaly... thanks a lot.
– Ravi
May 10 '17 at 12:33




Working Perfectaly... thanks a lot.
– Ravi
May 10 '17 at 12:33


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f43890477%2fdrag-and-drop-rows-of-datagrid-view-winform-c-sharp%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

Bressuire

Vorschmack

Quarantine