473,322 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Datagridview problem Help Needed


Question : How can I find actual row position of DataTable in
DataGridView when DataTable is sorted
/ My source code like this

Private WithEvent dgvInwDet as new DataGridView
Private WithEvent DataTable as New DataTable
Private Sub frmInward_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Handles MyBase.Load

'Configure DataGridView Style as Per Custome Requirement
ConfigerDataGridViewStyle()

'Create DataColumn in DataTable and DataGridView

'DataTable's Fields are
'ID, ShortCode, Name, Address, Editable
'DataGridView's Fields are
'ShortCode, Name, Address
'ID, Editable fields are hidden

CreateDataGridViewColumns()

'Index on 2 fields
InwDetTbl.DefaultView.Sort = "ShortCode ASC, Name ASC"

'Assign DataSource to DataGridView
dgvInwDet.DataSource = InwDetTbl

End Sub

Private Sub FillData()
'Fill Data in DataTable
Dim DataRow As DataRow

For iCtr = 0 to 100
DataRow = InwDetTbl.NewRow
DataRow.Item(0) = iCtr
DataRow.Item(1) = iCtr
DataRow.Item(2) = Name
DataRow.Item(3) = Address
DataRow.Item(4) = IsEditable() 'Return True or False
next

End Sub

Private Sub dgvInwDet_CellBeginEdit(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellCancelEventAr gs) Handles
dgvInwDet.CellBeginEdit
Try
e.Cancel = Not IsEditable(e.RowIndex)
Catch ex As Exception
ErrorMessage()
End Try
End Sub

Priavate Function IsEditable(nRowNo as integer) as Boolen
DIm lRetVal as boolen

'If i don't sort datatable, it works perfect,
'but if i made sort on datatable how can I found actual position in
DataTable

' In this case I found wrong position in CurrencyManager
if CInt(DataTable.Row(dgvInwDet.CurrentCell.RowIndex) .Item(0)) = 50
then
lRetVal = false
else
lRetVal = True
endif

Return lRetVal
end Function
If you have any Idea, Sample Code, Artical regarding above problem as
well as any information regarding DataGridView, Please send me on my
e-mail address.
ma***************@yahoo.co.in

May 5 '06 #1
1 3137
Sapkal,

Try forever to use the defaultview of the datatable as datasource.

If you are not possible to do that, than try the currencymanager. The
manager that keeps the current possition, not the money.

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

I hope this helps,

Cor

<sa***********@gmail.com> schreef in bericht
news:11**********************@u72g2000cwu.googlegr oups.com...

Question : How can I find actual row position of DataTable in
DataGridView when DataTable is sorted
/ My source code like this

Private WithEvent dgvInwDet as new DataGridView
Private WithEvent DataTable as New DataTable
Private Sub frmInward_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Handles MyBase.Load

'Configure DataGridView Style as Per Custome Requirement
ConfigerDataGridViewStyle()

'Create DataColumn in DataTable and DataGridView

'DataTable's Fields are
'ID, ShortCode, Name, Address, Editable
'DataGridView's Fields are
'ShortCode, Name, Address
'ID, Editable fields are hidden

CreateDataGridViewColumns()

'Index on 2 fields
InwDetTbl.DefaultView.Sort = "ShortCode ASC, Name ASC"

'Assign DataSource to DataGridView
dgvInwDet.DataSource = InwDetTbl

End Sub

Private Sub FillData()
'Fill Data in DataTable
Dim DataRow As DataRow

For iCtr = 0 to 100
DataRow = InwDetTbl.NewRow
DataRow.Item(0) = iCtr
DataRow.Item(1) = iCtr
DataRow.Item(2) = Name
DataRow.Item(3) = Address
DataRow.Item(4) = IsEditable() 'Return True or False
next

End Sub

Private Sub dgvInwDet_CellBeginEdit(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellCancelEventAr gs) Handles
dgvInwDet.CellBeginEdit
Try
e.Cancel = Not IsEditable(e.RowIndex)
Catch ex As Exception
ErrorMessage()
End Try
End Sub

Priavate Function IsEditable(nRowNo as integer) as Boolen
DIm lRetVal as boolen

'If i don't sort datatable, it works perfect,
'but if i made sort on datatable how can I found actual position in
DataTable

' In this case I found wrong position in CurrencyManager
if CInt(DataTable.Row(dgvInwDet.CurrentCell.RowIndex) .Item(0)) = 50
then
lRetVal = false
else
lRetVal = True
endif

Return lRetVal
end Function
If you have any Idea, Sample Code, Artical regarding above problem as
well as any information regarding DataGridView, Please send me on my
e-mail address.
ma***************@yahoo.co.in

May 5 '06 #2

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

Similar topics

0
by: TNSFED | last post by:
I have a dilemma when trying to delete a row from the DataGridView. Here is a sample of my code: private void dgv_EQUPS_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) {...
8
by: George | last post by:
Hi, I have been trying to see if I can do the following: 1. Create a DataGridView 2. Create 2 columns in the DataGridView (1 textbox and the other combobox) 3. Create a DataTable containing...
1
by: DBC User | last post by:
Hi All, I am using a database which doesn't suppport and since I am using ORM I can not use join query to create table object mapping. So my question is I have a master table which has bunch...
2
by: arch | last post by:
The datagridview comes with a small list of built-in column types that can be chosen from, eg DataGridViewTextBoxColumn, DataGridViewLinkColumn, DataGridViewImageColumn etc. But what I really...
2
by: Steve Richter | last post by:
what is the best way to use DataGridView to view data from large database tables? Where the sql select statement might return millions of rows? string connectionString =...
11
by: dave18 | last post by:
Hello all! I found a solution to my original question, but there's still so much I don't understand about it, I thought I'd give this forum a try. At the very least, maybe it will help someone...
6
by: hzgt9b | last post by:
Using VS2005, VB.NET, I have a windows app with a DataGridView (lets call it DGV). At some point in the life of my app I want to clear the selection of the currently selected row...
1
by: Tom | last post by:
First, I posted a similar request for help in another group and now don't find the posting. Problem with my newsreader perhaps ... but apologies if this appears as a cross posting. My code is...
3
by: jehugaleahsa | last post by:
Hello: I am binding a DataGridView with a BindingList<T>, where T is a custom business object that implements INotifyPropertyChanged. When you bind a DataGridView to a DataTable, it has this...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.