By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,934 Members | 1,366 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,934 IT Pros & Developers. It's quick & easy.

Need Your Opinion!

P: n/a
I'm writting an app that has two DataGridViews, in the first grid I
load a list on companies. Between the 2 grids are two buttons with
arrows, one points to the right the other to the left.
When the user selects rows from grid 1 (on the left) and clicks the
arrow pointing to the right, it moves the rows to the other
DataGridView.

The user is basically selecting companies to print out invoices for.
The grid on the right is the list of "selected" companies to process.

Here is the issue I'm having.

At first I was using a SqlDataReader object to get a list of companies
and adding the results to the DataGridView like so:

While Reader.Read
Values(0) = Reader(0)
Values(1) = Reader(1)
dgv_Companies.Rows.Add(Values)
End While

The issue here is when the user selects a bunch of rows from grid 1
and I use this code to move them to grid 2:

Private Sub MoveDataGridViewRows(ByVal Source As DataGridView, ByVal
Destination As DataGridView)

If Source.Rows.Count = 0 Then Exit Sub
If Source.SelectedRows.Count = 0 Then Exit Sub

Dim SelectedRow As DataGridViewRow
Dim ColumnCount As Int32 = Source.Columns.Count - 1
Dim Values(ColumnCount) As String
Dim i As Int32

For Each SelectedRow In Source.SelectedRows
For i = 0 To ColumnCount
Values(i) = SelectedRow.Cells(i).Value
Next
Destination.Rows.Add(Values)
Source.Rows.Remove(SelectedRow)
Next

Destination.Sort(Destination.Columns(0),
System.ComponentModel.ListSortDirection.Ascending)
End Sub

It only moves the rows at a rate of about 2 or 3 per second, so when
2200 rows are selected....it takes a while.

So I thought I would bind the DataGridViews to DataTables and use
ADO.NET and hopefully move rows quicker. The issues so far have been:

1) Data needs to be organized in ascending order by column1
(CompanyName), when rows get added to the "selected companies" table
they are not in order, they get appended to the bottom of the
datatable.
2) Using the DefaultView of the DataTable doesn't work too good for
ordering the rows because it only reorders the VIEW of the table and
not the physical order of the table. So when I do
DataGridView.SelectedRows() the index of the selected rows in the
datagridview control is different then the index of the actual rows in
the datatable. That's a little confusing but if you've had experience
with this you'll know what I'm talking about.

So I'd like to get some ideas from anyone on how to accomplish this
task with performance in mind. I really don't mind using different
controls if that is what is necessary, just keep in mind these
requirements:

1) The data in both grids needs to be kept in ascending order by
CompanyName. So when a row get moved from either side it needs to be
placed in the right location in the grid.
2) Users need the ability to select multiple rows and move them all at
once.

Please only people who are serious about sharing ideas need to
respond!

Thanks for your help!
Izzy

Jan 30 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Izzy,

In version 1.x I would direct tell you that you could have a look at the
dataview to improve what you are doing. Especially because the dataview is
improved in 2.0.

However some of its habbits are now integretated in the bindingsource.
http://msdn2.microsoft.com/en-us/lib...urce.sort.aspx

Therefore have a look at that first,

Cor
"Izzy" <is************@gmail.comschreef in bericht
news:11**********************@v33g2000cwv.googlegr oups.com...
I'm writting an app that has two DataGridViews, in the first grid I
load a list on companies. Between the 2 grids are two buttons with
arrows, one points to the right the other to the left.
When the user selects rows from grid 1 (on the left) and clicks the
arrow pointing to the right, it moves the rows to the other
DataGridView.

The user is basically selecting companies to print out invoices for.
The grid on the right is the list of "selected" companies to process.

Here is the issue I'm having.

At first I was using a SqlDataReader object to get a list of companies
and adding the results to the DataGridView like so:

While Reader.Read
Values(0) = Reader(0)
Values(1) = Reader(1)
dgv_Companies.Rows.Add(Values)
End While

The issue here is when the user selects a bunch of rows from grid 1
and I use this code to move them to grid 2:

Private Sub MoveDataGridViewRows(ByVal Source As DataGridView, ByVal
Destination As DataGridView)

If Source.Rows.Count = 0 Then Exit Sub
If Source.SelectedRows.Count = 0 Then Exit Sub

Dim SelectedRow As DataGridViewRow
Dim ColumnCount As Int32 = Source.Columns.Count - 1
Dim Values(ColumnCount) As String
Dim i As Int32

For Each SelectedRow In Source.SelectedRows
For i = 0 To ColumnCount
Values(i) = SelectedRow.Cells(i).Value
Next
Destination.Rows.Add(Values)
Source.Rows.Remove(SelectedRow)
Next

Destination.Sort(Destination.Columns(0),
System.ComponentModel.ListSortDirection.Ascending)
End Sub

It only moves the rows at a rate of about 2 or 3 per second, so when
2200 rows are selected....it takes a while.

So I thought I would bind the DataGridViews to DataTables and use
ADO.NET and hopefully move rows quicker. The issues so far have been:

1) Data needs to be organized in ascending order by column1
(CompanyName), when rows get added to the "selected companies" table
they are not in order, they get appended to the bottom of the
datatable.
2) Using the DefaultView of the DataTable doesn't work too good for
ordering the rows because it only reorders the VIEW of the table and
not the physical order of the table. So when I do
DataGridView.SelectedRows() the index of the selected rows in the
datagridview control is different then the index of the actual rows in
the datatable. That's a little confusing but if you've had experience
with this you'll know what I'm talking about.

So I'd like to get some ideas from anyone on how to accomplish this
task with performance in mind. I really don't mind using different
controls if that is what is necessary, just keep in mind these
requirements:

1) The data in both grids needs to be kept in ascending order by
CompanyName. So when a row get moved from either side it needs to be
placed in the right location in the grid.
2) Users need the ability to select multiple rows and move them all at
once.

Please only people who are serious about sharing ideas need to
respond!

Thanks for your help!
Izzy

Jan 31 '07 #2

P: n/a
Why don't you just have one grid, and add a column on the left hand side
and let them set it to Y or X if they want to print out an invoice for that
row. And I would see if there's a way to change the background color of
that row, so they can easily visually tell. I'm sure there's a way to do
that, but it's too late for me to go figure it out. If you can't figure it
out, re-post and ask and I'll see what I can find.

Then you don't have to deal with the two grids and moving records at all.

Robin S.
----------------------------------------------------------
"Izzy" <is************@gmail.comwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...
I'm writting an app that has two DataGridViews, in the first grid I
load a list on companies. Between the 2 grids are two buttons with
arrows, one points to the right the other to the left.
When the user selects rows from grid 1 (on the left) and clicks the
arrow pointing to the right, it moves the rows to the other
DataGridView.

The user is basically selecting companies to print out invoices for.
The grid on the right is the list of "selected" companies to process.

Here is the issue I'm having.

At first I was using a SqlDataReader object to get a list of companies
and adding the results to the DataGridView like so:

While Reader.Read
Values(0) = Reader(0)
Values(1) = Reader(1)
dgv_Companies.Rows.Add(Values)
End While

The issue here is when the user selects a bunch of rows from grid 1
and I use this code to move them to grid 2:

Private Sub MoveDataGridViewRows(ByVal Source As DataGridView, ByVal
Destination As DataGridView)

If Source.Rows.Count = 0 Then Exit Sub
If Source.SelectedRows.Count = 0 Then Exit Sub

Dim SelectedRow As DataGridViewRow
Dim ColumnCount As Int32 = Source.Columns.Count - 1
Dim Values(ColumnCount) As String
Dim i As Int32

For Each SelectedRow In Source.SelectedRows
For i = 0 To ColumnCount
Values(i) = SelectedRow.Cells(i).Value
Next
Destination.Rows.Add(Values)
Source.Rows.Remove(SelectedRow)
Next

Destination.Sort(Destination.Columns(0),
System.ComponentModel.ListSortDirection.Ascending)
End Sub

It only moves the rows at a rate of about 2 or 3 per second, so when
2200 rows are selected....it takes a while.

So I thought I would bind the DataGridViews to DataTables and use
ADO.NET and hopefully move rows quicker. The issues so far have been:

1) Data needs to be organized in ascending order by column1
(CompanyName), when rows get added to the "selected companies" table
they are not in order, they get appended to the bottom of the
datatable.
2) Using the DefaultView of the DataTable doesn't work too good for
ordering the rows because it only reorders the VIEW of the table and
not the physical order of the table. So when I do
DataGridView.SelectedRows() the index of the selected rows in the
datagridview control is different then the index of the actual rows in
the datatable. That's a little confusing but if you've had experience
with this you'll know what I'm talking about.

So I'd like to get some ideas from anyone on how to accomplish this
task with performance in mind. I really don't mind using different
controls if that is what is necessary, just keep in mind these
requirements:

1) The data in both grids needs to be kept in ascending order by
CompanyName. So when a row get moved from either side it needs to be
placed in the right location in the grid.
2) Users need the ability to select multiple rows and move them all at
once.

Please only people who are serious about sharing ideas need to
respond!

Thanks for your help!
Izzy

Jan 31 '07 #3

P: n/a
In response to Robin, they want 2 grids. If there were only going to
be 10 or 20 item in the list I'd say that would be a good option but
in my case were talking about 2200 items in the list. So expecting the
user to scroll through 2200 item to find out which 5 he selected is
not really an option.

I do appreciate the ideas.

Cor - I'll check out the DataView, I've been messing with the listbox
control and it does move items very fast, I just don't like the
appearance of it. Looks like something a caveman would use. :-) I'll
let you know how the DataView goes.

I'm even considering making two physical tables within my SQL Server
to store the data.....or possibly two global temp tables then just
drop them when the app closes. What are your thoughts on that Cor?

Jan 31 '07 #4

P: n/a
On Jan 30, 6:48 pm, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:
Izzy,

In version 1.x I would direct tell you that you could have a look at the
dataview to improve what you are doing. Especially because the dataview is
improved in 2.0.

However some of its habbits are now integretated in the bindingsource.http://msdn2.microsoft.com/en-us/lib....forms.binding...

Therefore have a look at that first,

Cor

"Izzy" <israel.rich...@gmail.comschreef in berichtnews:11**********************@v33g2000cwv.g ooglegroups.com...
I'm writting an app that has two DataGridViews, in the first grid I
load a list on companies. Between the 2 grids are two buttons with
arrows, one points to the right the other to the left.
When the user selects rows from grid 1 (on the left) and clicks the
arrow pointing to the right, it moves the rows to the other
DataGridView.
The user is basically selecting companies to print out invoices for.
The grid on the right is the list of "selected" companies to process.
Here is the issue I'm having.
At first I was using a SqlDataReader object to get a list of companies
and adding the results to the DataGridView like so:
While Reader.Read
Values(0) = Reader(0)
Values(1) = Reader(1)
dgv_Companies.Rows.Add(Values)
End While
The issue here is when the user selects a bunch of rows from grid 1
and I use this code to move them to grid 2:
Private Sub MoveDataGridViewRows(ByVal Source As DataGridView, ByVal
Destination As DataGridView)
If Source.Rows.Count = 0 Then Exit Sub
If Source.SelectedRows.Count = 0 Then Exit Sub
Dim SelectedRow As DataGridViewRow
Dim ColumnCount As Int32 = Source.Columns.Count - 1
Dim Values(ColumnCount) As String
Dim i As Int32
For Each SelectedRow In Source.SelectedRows
For i = 0 To ColumnCount
Values(i) = SelectedRow.Cells(i).Value
Next
Destination.Rows.Add(Values)
Source.Rows.Remove(SelectedRow)
Next
Destination.Sort(Destination.Columns(0),
System.ComponentModel.ListSortDirection.Ascending)
End Sub
It only moves the rows at a rate of about 2 or 3 per second, so when
2200 rows are selected....it takes a while.
So I thought I would bind the DataGridViews to DataTables and use
ADO.NET and hopefully move rows quicker. The issues so far have been:
1) Data needs to be organized in ascending order by column1
(CompanyName), when rows get added to the "selected companies" table
they are not in order, they get appended to the bottom of the
datatable.
2) Using the DefaultView of the DataTable doesn't work too good for
ordering the rows because it only reorders the VIEW of the table and
not the physical order of the table. So when I do
DataGridView.SelectedRows() the index of the selected rows in the
datagridview control is different then the index of the actual rows in
the datatable. That's a little confusing but if you've had experience
with this you'll know what I'm talking about.
So I'd like to get some ideas from anyone on how to accomplish this
task with performance in mind. I really don't mind using different
controls if that is what is necessary, just keep in mind these
requirements:
1) The data in both grids needs to be kept in ascending order by
CompanyName. So when a row get moved from either side it needs to be
placed in the right location in the grid.
2) Users need the ability to select multiple rows and move them all at
once.
Please only people who are serious about sharing ideas need to
respond!
Thanks for your help!
Izzy- Hide quoted text -

- Show quoted text -
While playing with the DataView I discovered where the slow down was.
The slow down happens at this line of code in my original post:

Source.Rows.Remove(SelectedRow)

Actually moving rows happens very fast, deleting rows from the Source
grid is the slow part, its very slow.

Any ideas on how to quickly remove rows from the source grid after
they have been copies to the destination grid?

Jan 31 '07 #5

P: n/a
On Jan 31, 11:08 am, "Izzy" <israel.rich...@gmail.comwrote:
On Jan 30, 6:48 pm, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:
Izzy,
In version 1.x I would direct tell you that you could have a look at the
dataview to improve what you are doing. Especially because the dataview is
improved in 2.0.
However some of its habbits are now integretated in the bindingsource.http://msdn2.microsoft.com/en-us/lib....forms.binding...
Therefore have a look at that first,
Cor
"Izzy" <israel.rich...@gmail.comschreef in berichtnews:11**********************@v33g2000cwv.g ooglegroups.com...
I'm writting an app that has two DataGridViews, in the first grid I
load a list on companies. Between the 2 grids are two buttons with
arrows, one points to the right the other to the left.
When the user selects rows from grid 1 (on the left) and clicks the
arrow pointing to the right, it moves the rows to the other
DataGridView.
The user is basically selecting companies to print out invoices for.
The grid on the right is the list of "selected" companies to process.
Here is the issue I'm having.
At first I was using a SqlDataReader object to get a list of companies
and adding the results to the DataGridView like so:
While Reader.Read
Values(0) = Reader(0)
Values(1) = Reader(1)
dgv_Companies.Rows.Add(Values)
End While
The issue here is when the user selects a bunch of rows from grid 1
and I use this code to move them to grid 2:
Private Sub MoveDataGridViewRows(ByVal Source As DataGridView, ByVal
Destination As DataGridView)
If Source.Rows.Count = 0 Then Exit Sub
If Source.SelectedRows.Count = 0 Then Exit Sub
Dim SelectedRow As DataGridViewRow
Dim ColumnCount As Int32 = Source.Columns.Count - 1
Dim Values(ColumnCount) As String
Dim i As Int32
For Each SelectedRow In Source.SelectedRows
For i = 0 To ColumnCount
Values(i) = SelectedRow.Cells(i).Value
Next
Destination.Rows.Add(Values)
Source.Rows.Remove(SelectedRow)
Next
Destination.Sort(Destination.Columns(0),
System.ComponentModel.ListSortDirection.Ascending)
End Sub
It only moves the rows at a rate of about 2 or 3 per second, so when
2200 rows are selected....it takes a while.
So I thought I would bind the DataGridViews to DataTables and use
ADO.NET and hopefully move rows quicker. The issues so far have been:
1) Data needs to be organized in ascending order by column1
(CompanyName), when rows get added to the "selected companies" table
they are not in order, they get appended to the bottom of the
datatable.
2) Using the DefaultView of the DataTable doesn't work too good for
ordering the rows because it only reorders the VIEW of the table and
not the physical order of the table. So when I do
DataGridView.SelectedRows() the index of the selected rows in the
datagridview control is different then the index of the actual rows in
the datatable. That's a little confusing but if you've had experience
with this you'll know what I'm talking about.
So I'd like to get some ideas from anyone on how to accomplish this
task with performance in mind. I really don't mind using different
controls if that is what is necessary, just keep in mind these
requirements:
1) The data in both grids needs to be kept in ascending order by
CompanyName. So when a row get moved from either side it needs to be
placed in the right location in the grid.
2) Users need the ability to select multiple rows and move them all at
once.
Please only people who are serious about sharing ideas need to
respond!
Thanks for your help!
Izzy- Hide quoted text -
- Show quoted text -

While playing with the DataView I discovered where the slow down was.
The slow down happens at this line of code in my original post:

Source.Rows.Remove(SelectedRow)

Actually moving rows happens very fast, deleting rows from the Source
grid is the slow part, its very slow.

Any ideas on how to quickly remove rows from the source grid after
they have been copies to the destination grid?
Could you cheat and just set the row height to zero? (or maybe there
is a visible property - I'm not in VS right now or I'd check)

Thanks,

Seth Rowe
Jan 31 '07 #6

P: n/a
Yeah, I understand that. I'm sure you'll be able to figure out how to get
it to work. It just takes a little persistence.

Robin S.
---------
"Izzy" <is************@gmail.comwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...
In response to Robin, they want 2 grids. If there were only going to
be 10 or 20 item in the list I'd say that would be a good option but
in my case were talking about 2200 items in the list. So expecting the
user to scroll through 2200 item to find out which 5 he selected is
not really an option.

I do appreciate the ideas.

Cor - I'll check out the DataView, I've been messing with the listbox
control and it does move items very fast, I just don't like the
appearance of it. Looks like something a caveman would use. :-) I'll
let you know how the DataView goes.

I'm even considering making two physical tables within my SQL Server
to store the data.....or possibly two global temp tables then just
drop them when the app closes. What are your thoughts on that Cor?

Jan 31 '07 #7

P: n/a
On Jan 31, 11:37 am, "RobinS" <Rob...@NoSpam.yah.nonewrote:
Yeah, I understand that. I'm sure you'll be able to figure out how to get
it to work. It just takes a little persistence.

Robin S.
---------"Izzy" <israel.rich...@gmail.comwrote in message

news:11**********************@q2g2000cwa.googlegro ups.com...
In response to Robin, they want 2 grids. If there were only going to
be 10 or 20 item in the list I'd say that would be a good option but
in my case were talking about 2200 items in the list. So expecting the
user to scroll through 2200 item to find out which 5 he selected is
not really an option.
I do appreciate the ideas.
Cor - I'll check out the DataView, I've been messing with the listbox
control and it does move items very fast, I just don't like the
appearance of it. Looks like something a caveman would use. :-) I'll
let you know how the DataView goes.
I'm even considering making two physical tables within my SQL Server
to store the data.....or possibly two global temp tables then just
drop them when the app closes. What are your thoughts on that Cor?- Hide quoted text -

- Show quoted text -
Well here's what I did, I tried setting the row.visible property to
false but that took just as long as deleting the row. I even tried
deleting the row with SuspendLayout enabled.....no difference. Tried
deleting from the DataView but still had to loop through every
selected row in the DataGridView to get the index....so no help.

I switched out the DataGridView with an Infragistics Grid and Kazzzzam
it works great. Here is the code I'm using with the new grids.

Private Sub MoveRow(ByVal Source As
Infragistics.Win.UltraWinGrid.UltraGrid, ByVal Dest As
Infragistics.Win.UltraWinGrid.UltraGrid)

Dim dtSource As DataTable = Source.DataSource
Dim dtDest As DataTable = Dest.DataSource
Dim SelectedRow As Infragistics.Win.UltraWinGrid.UltraGridRow
Dim RowToAdd As DataRow
Dim i As Int32

For Each SelectedRow In Source.Selected.Rows
RowToAdd = dtDest.NewRow
For i = 0 To dtSource.Columns.Count - 1
RowToAdd(i) = SelectedRow.Cells(i).Value
Next
dtDest.Rows.Add(RowToAdd)
Next

Do Until Source.Selected.Rows.Count = 0
Source.Selected.Rows(0).Delete(False)
Loop

End Sub

All 2200 rows move in less than a second. I was trying to get familiar
with Microsofts DataGridView hoping it was an imporvement over the
VS2003 version of DataGrid. No luck there....back to Infragistics!

Thanks to everyone who responded.

Jan 31 '07 #8

P: n/a

"Izzy" <is************@gmail.comwrote in message
news:11**********************@h3g2000cwc.googlegro ups.com...
On Jan 31, 11:37 am, "RobinS" <Rob...@NoSpam.yah.nonewrote:
>Yeah, I understand that. I'm sure you'll be able to figure out how to
get
it to work. It just takes a little persistence.

Robin S.
---------"Izzy" <israel.rich...@gmail.comwrote in message

news:11**********************@q2g2000cwa.googlegr oups.com...
In response to Robin, they want 2 grids. If there were only going to
be 10 or 20 item in the list I'd say that would be a good option but
in my case were talking about 2200 items in the list. So expecting the
user to scroll through 2200 item to find out which 5 he selected is
not really an option.
I do appreciate the ideas.
Cor - I'll check out the DataView, I've been messing with the listbox
control and it does move items very fast, I just don't like the
appearance of it. Looks like something a caveman would use. :-) I'll
let you know how the DataView goes.
I'm even considering making two physical tables within my SQL Server
to store the data.....or possibly two global temp tables then just
drop them when the app closes. What are your thoughts on that Cor?-
Hide quoted text -

- Show quoted text -

Well here's what I did, I tried setting the row.visible property to
false but that took just as long as deleting the row. I even tried
deleting the row with SuspendLayout enabled.....no difference. Tried
deleting from the DataView but still had to loop through every
selected row in the DataGridView to get the index....so no help.

I switched out the DataGridView with an Infragistics Grid and Kazzzzam
it works great. Here is the code I'm using with the new grids.

Private Sub MoveRow(ByVal Source As
Infragistics.Win.UltraWinGrid.UltraGrid, ByVal Dest As
Infragistics.Win.UltraWinGrid.UltraGrid)

Dim dtSource As DataTable = Source.DataSource
Dim dtDest As DataTable = Dest.DataSource
Dim SelectedRow As Infragistics.Win.UltraWinGrid.UltraGridRow
Dim RowToAdd As DataRow
Dim i As Int32

For Each SelectedRow In Source.Selected.Rows
RowToAdd = dtDest.NewRow
For i = 0 To dtSource.Columns.Count - 1
RowToAdd(i) = SelectedRow.Cells(i).Value
Next
dtDest.Rows.Add(RowToAdd)
Next

Do Until Source.Selected.Rows.Count = 0
Source.Selected.Rows(0).Delete(False)
Loop

End Sub

All 2200 rows move in less than a second. I was trying to get familiar
with Microsofts DataGridView hoping it was an imporvement over the
VS2003 version of DataGrid. No luck there....back to Infragistics!

Thanks to everyone who responded.
Thanks for letting us know how you resolved the problem.

Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
Feb 1 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.