473,761 Members | 10,498 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

translate current cell (row, column) in sorted datagrid to corresponding row/col in datatable

I have a datatable as the datasource to a datagrid. The datagrid has a
datagridtablest yle defined. I use the datagridtablest yle 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 datagrid.HitTes tInfo I can easily find out the row and column of
the datagrid (ie: hti.row and hti.column). Now I need to find the
corresponding row and column for the cell the user clicked on in the actual
datatable . I need to do this in the MOUSEDOWN event.

As an initial thought, I used a Dim bm as BindingManagerB ase like this:

bm = Me.dg.BindingCo ntext(Me.dg.Dat aSource)

However, it seems that the datarow accessed by ctype(bm.curren t,
datarowview) points to the row just before the user clicked the mouse on
the new cell. The mousedown event seems to take control before the
bm.current row is updated.

Anyway, all this means that I am now totally confused. Clearly there must
be a procedure to translate the datagrid row/column to the datatable
row/column because you can rearrange columns and sort them to your hearts
content, and when you then change the value of a cell in the datagrid, it
updates the proper row/column in the datatable. SO HOW DOES IT DO IT???

Is there some sort of function or formula that will return the datatable
row/column given the datagrid row/column??? It would be great to have
something like: RowInDatatable = ConvertToDataTa bleRow(RowInDat aGrid).

I would appreciate any guidance on this.
Thanks, John


Nov 21 '05
10 4952
Hi Cor,

Thanks for the link... The new grid looks great. Can't wait for the
..NET 2005 release.

John
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
JohnR,

Maybe can this helps you in future, I do really know nothing from it.

http://msdn.microsoft.com/library/de...tml/vs05a9.asp
Cor



"JohnR" <Jo******@hotma il.com> schreef in bericht
news:RH4le.346$ Fb.106@trndny07 ...
Hi Cor,

Well, actually, I have a very good reason (I believe) to be able to
track the datagrid row/col back to the datatable and here it is...

I actually have two datatables that mirror each other. Let's say they
both have columns of "FEATURE" and "VALUE". In the first datatable the
VALUE column is of type "string". In the second datatable the VALUE is
of type "object". I use the first datatable as a datasource for the
datagrid, and the grid displays strings in each of the columns. Some
sample rows might be something like:

FEATURE VALUE
Security Yes
Combinations <click for more info>
Last Access 5/4/2005

Notice the <click for more info> text in the 2nd row, 2nd col. The
corresponding row/col in the 2nd datatable (the one that stores the VALUE
column as type 'object') is an instance of a custom class.

Now, here's the fun part. When the user clicks on the cell that has the
string <click for more info> I then go to the corresponding row/col in
the 2nd datatable and get the object that has the instance of the custom
class and then process it.

When the datagrid is not sorted and the columns and rows correspond
exactly to the datatable this process works perfectly.

BUT, if the datagrid is sorted and/or column are rearranged, then I need
the row/col of the cell that maps back into the datatable so that I can
fetch the corresponding OBJECT in the 2nd datatable. This is why I need
to know the mapping of grid row/col to datatable row/col.

So, I hope you can see that the requirement is actually not ridiculous...
there was some serious thought behind it.

Regards,
John



"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** *******@TK2MSFT NGP15.phx.gbl.. .
John,

You were asking in my opinon two questions, how is the sort order done
and how you can get from your datagrid to your cel in the datatable. The
first I could answer the second is for me a kind of rediculous, it is
the same for me as asking how you can use a plane to sail over the
oceans. A datagrid is not build for that, it is not a stand alone grid.

You cannot translate the current row/cell in a datagrid to a
current/cell in a datatable.

A datagrid is not a classic grid. It is a table of rows which has shows
items. Using the column mapping the right cell is found. However changes
in data goes row by row after that the user has commited by a row change
that he has done that row. (Or a button which has an endcurrentedit
behind it).

In other words a datagrid uses rows and items from a datasource, which
is placed using the mapping on the screen.

You can not see in the datasource what the UI is doing. Like that you
cannot see in a datagrid what the datasource is doing. Until that both
have done what they have to do.

You can however see what is the currentrow in the datagrid. For that is
the currencymanager .

http://msdn.microsoft.com/library/de...classtopic.asp

You told that you have seen a lot of questions from people who wants to
use a Grid in dotNet on the classic way. Mostly that people are after a
while glad that there is now a better datagrid.

However just my thought,

Cor



Nov 21 '05 #11

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

Similar topics

2
1805
by: mrstrong | last post by:
Gday, Am new to using datagrids so if anyone could assist or point in the right direction in terms of resources - that would be much appreciated... I have a form that has: - a datagrid that displays summary data - other controls (eg textboxes, comboboxes) that are editable
3
2604
by: Michael Schindler | last post by:
Hello NG How I can delete a specific cell in my Datagrid. I would like if the user is in the column 6 the value changed, after automaticly the value in the column 7 in the same row to delete. Thanks
4
5443
by: Randy | last post by:
I have a DataTable in a DataGrid. If I click on the DataGrid, HitTestInfo in dataGrid1_MouseDown returns a Row and Column number. I can use the Row number to say: DataRow dr = dataTable.Rows; Of course, I get completely the wrong row of data if the user has sorted the table by clicking any of the column headers.
4
2843
by: Steve B. | last post by:
I have a DataGrid on the left and TextBoxes (TB) on the right. The TB's reflect the contents of the grid cells. Sorting of columns (both thru VS and programmatically) work fine except, when the form/grid first opens up and the grid is immediately sorted the TB don't reflect the sorted data of the First row of the grid. Note: Initially the black grid indicator arrow points to the first row. If the user choses another row and then sorts...
1
1601
by: Raul Cortes | last post by:
Hi. I am using a windowsform datagrid to modify a table. The DataSet seems to be filled fined. The DataTable seems to be ok. I am not using 'read only' anywhere. The DataSource seems to be well asigned. The DataMenber assigned to the table. One column of the DataSet is decimal type.
0
1387
by: Ben | last post by:
module main ... application.run(new splashform) .. end module after a few screen, I try to load a new codes I got from MSDN on datagrid that works on its own. I took out submain and ran datagridForm from my mainForm:
2
6718
by: fripper | last post by:
After a good bit of urging from folks in this newsgroup I have begun to become familiar with the VB .Net DataGrid control as a replacement for one my favorite VB6 controls ... the FlexGrid. In any event, I have a DataGrid, added a GridTableStyle, bound a DataTable to it and everything displays pretty well. Now, sometimes when the user clicks on a cell I would like to be able to determine the row/column number and set the foreground and...
7
3118
by: Arne Beruldsen | last post by:
in vbnet2005 I have a datagridview. When the user clicks on a row...I would like the contents of certain cells to populate a textbox. To do this...i need to be able to refer to the row and colums...something like textbox = contents (rx, cx) How can I refer to the cell contents? Thanks....
12
13646
by: cj | last post by:
When viewing a datatable in a datagridview one of the columns in it is a "note" field which can be quite long. I would like to have the note field of the currently selected row of the datagrid display in a textbox below the datgridview. I currently have it fixed so if you click on a row the note field from that row is put in the textbox. I'd like this to be automatic as they move through rows. Also the note field is one of two fields...
0
9521
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...
1
9900
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
9765
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
6599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5214
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
5361
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3863
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
3
3442
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.