PC Review


Reply
Thread Tools Rate Thread

dataGridView + dataSet in ADO.NET 2.0

 
 
=?Utf-8?B?RnJpZWRoZWxtIERyZWNrdHJhaA==?=
Guest
Posts: n/a
 
      9th Dec 2005
Hi,
I have a dataGridView databinded to a dataSet. The Rows are in a specific
order and I want to swap the selected row with the row below it. I have a
RowNum (int) Field in the database. How can I do this?

Thanks, Friedhelm Drecktrah
 
Reply With Quote
 
 
 
 
=?Utf-8?B?RnJpZWRoZWxtIERyZWNrdHJhaA==?=
Guest
Posts: n/a
 
      9th Dec 2005
b.t.w.: I use C#.

"Friedhelm Drecktrah" wrote:

> Hi,
> I have a dataGridView databinded to a dataSet. The Rows are in a specific
> order and I want to swap the selected row with the row below it. I have a
> RowNum (int) Field in the database. How can I do this?
>
> Thanks, Friedhelm Drecktrah

 
Reply With Quote
 
Bart Mermuys
Guest
Posts: n/a
 
      9th Dec 2005
Hi,

"Friedhelm Drecktrah" <(E-Mail Removed)> wrote
in message news:0298FB59-6DAB-42DE-81B8-(E-Mail Removed)...
> Hi,
> I have a dataGridView databinded to a dataSet. The Rows are in a specific
> order and I want to swap the selected row with the row below it. I have a
> RowNum (int) Field in the database. How can I do this?


If RowNum is also a column inside a DataTable of dataSet and that column
specifies the order then you could start by adding a BindingSource between
the DataSet and DataGridView if you haven't already (from code or with the
designer):

bindingSource1.DataSource = dataSet;
bindingSource1.DataMember = "tablename";
bindingSource1.Sort = "RowNum";

dataGridView.DataSource = bindingSource1;
dataGridView.DataMember = "";

Then you can use this code:

public void SwapRows()
{
DataView dv = (DataView)bindingSource1.List;

if (bindingSource1.Position + 1 < dv.Count)
{
DataRow dr1 = dv[bindingSource1.Position].Row;
DataRow dr2 = dv[bindingSource1.Position + 1].Row;

int rowNum1 = (int)dr1["RowNum"];
int rowNum2 = (int)dr2["RowNum"];

dr1["RowNum"] = -1; // avoid pos. constraint errors
dr2["RowNum"] = rowNum1;
dr1["RowNum"] = rowNum2;
}
}


HTH,
Greetings


>
> Thanks, Friedhelm Drecktrah



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataSet into DataGridView Scott Spence Microsoft VB .NET 2 7th Jan 2010 08:36 PM
DataSet and DataGridView Oliver Microsoft C# .NET 7 6th Apr 2009 10:39 PM
Dataset's - datagridview help Tony M Microsoft VB .NET 1 27th Aug 2008 06:09 PM
How put a Dataset in a Datagridview Freddy Coal Microsoft VB .NET 3 27th Oct 2007 06:48 AM
how to get the data from the datagridview into the dataset cEciLlE Microsoft ADO .NET 0 18th Jan 2005 03:37 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:46 AM.