472,342 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 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 3044
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...
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...
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...
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,...
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? ...
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....
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...
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...
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...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

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.