473,657 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datagrid vs. datatable rows

Jon
Question: does datagrid1.isSel ected(i) point to the same
row as datatable.row(i ).delete after datagrid sorted??
I am using datagrid1.isSel ected(i) to identify datatable rows that
have been selected by the user

Then I use datatable.rows( i).delete to delete those rows.

It works fine if I have not sorted the datatable first. But if
I do sort it, then the row index identified in the
datagrid.isSele cted(i) code
is not the same row deleted in the
datatable.rows( i).deleted code.

The section of code is below.
'get ids of selected rows store in array selected
For i = 1 To dt_data.Rows.Co unt
If DataGrid1.IsSel ected(i - 1) Then
nselected += 1
selected(nselec ted) = i
End If
Next

'dele and transfer each selected but in reverse order
For i = nselected To 1 Step -1
' Remove row from datagrid
dt_data.Rows(se lected(i) - 1).Delete()
Next i
Nov 21 '05 #1
1 4562
Jon,

Your question is one of the reasons why you can better take a dataview as
the datasource for a datagrid. (And use the currencymanager as well)

I hope this helps?

Cor

"Jon" <Jo*@discussion s.microsoft.com >
Question: does datagrid1.isSel ected(i) point to the same
row as datatable.row(i ).delete after datagrid sorted??
I am using datagrid1.isSel ected(i) to identify datatable rows that
have been selected by the user

Then I use datatable.rows( i).delete to delete those rows.

It works fine if I have not sorted the datatable first. But if
I do sort it, then the row index identified in the
datagrid.isSele cted(i) code
is not the same row deleted in the
datatable.rows( i).deleted code.

The section of code is below.
'get ids of selected rows store in array selected
For i = 1 To dt_data.Rows.Co unt
If DataGrid1.IsSel ected(i - 1) Then
nselected += 1
selected(nselec ted) = i
End If
Next

'dele and transfer each selected but in reverse order
For i = nselected To 1 Step -1
' Remove row from datagrid
dt_data.Rows(se lected(i) - 1).Delete()
Next i

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2097
by: Newbie | last post by:
I am using a Datagrid to show the contents of a DataTable. But it seems like the Datagrid is not getting the contents of the Datatable when the button ( btnAddAnotherLaborCategory) is clicked. private void Page_Load(object sender, System.EventArgs e) { DataTable dataTable; DataColumn dataColumn; DataRow dataRow; dataTable = new DataTable("ratesTable");
5
12229
by: John Richardson | last post by:
I've been bothered for some time about my DataGrid not populating my rows very quickly. I have about 10K rows loading into the grid. I create a datatable dt with 2 columns, an ID and a display. The ID is a member of the keys array. I then create a DataView dv over the table, and sort it by Display and ID column (in case of duplicate Display). I then set my DataGrid.DataSource = dv; I then load the datatable with my rows, and this is...
4
5351
by: Glenn Owens | last post by:
I have a DataGrid web control which I've dynamically populated with template columns to be used for bulk-editting. Generally, all of the columns are textbox and/or dropdownlist child controls. Currently everything is working. I can find the updated rows/columns by parsing the posted data collection against the DataGrid DataSource. However, when there is a large amount of DataGridItems (rows) the update processing can take a while. ...
1
3278
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple days of struggling, I figure asking you all (the experts) will keep me from going down some dark and dangerous road. The project I have is a fairly simple one, in theory anyway. The gist is to create a page where the user enters an IDNumber,...
4
3487
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a snippet from my .css file: *************************** body { margin:0; padding:0;
8
2026
by: Strahimir Antoljak | last post by:
I bound a DataGrid to a table (I tried with a DataView too). I removed the row from the table, and then inserted a new row at the same row index. the table gets the row to the right position, but the bound DataGrid does not pick up and appends the inserted row at the bottom of the grid, not the right position?!? Any ideas how to make the DataGrid pick up the changes done in the table - to show the inserted row at the right position?
8
3921
by: Richard L Rosenheim | last post by:
I have a dataset containing a parent table related to a child table. The child table contains an ID field (which is configured as autonumber in the datatable), the ID of the parent, plus some addition fields. I'm able to get the datagrid to be properly populate with only the child records relating to the specified parent by setting the ..DefaultView.RowFilter property. Currently, to properly add a new child record, I need to manually...
4
2279
by: Jan Nielsen | last post by:
Hi all I'm a former Access developer who would like to implement a many-to-many relation in about the same way you do in Access: With a subform and a combo box. Is it possible to use a combobox in a datagrid? Any other suggestions/articles on how to implement many-many relations in the frontend (which of course are 2 one-many relations)?
3
2515
by: Datatable Dataset Datagrid help | last post by:
Hi I am somewhat confused, I am new at VB.net I use XML data, I have a datagrid, I created a datatable so that I can create a custom format like true is this graphic false is this graphic and others. One of the custom format is as follows: dsmessages_dt.Columns.Add("Image", GetType(Image)) I had a problem of when I used a checkbox in the grid that was bound to the datatable that it would not update my dataset. So I created another...
10
4941
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than the column order of the datatable). I also allow the user to click on a column header to sort the datagrid by that column. I need to identify the row and column in the datatable when the user clicks on a cell in the datagrid. Using the...
0
8411
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8323
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8838
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8613
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.