473,700 Members | 2,424 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.EventArg s)
Handles MyBase.Load

'Configure DataGridView Style as Per Custome Requirement
ConfigerDataGri dViewStyle()

'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

CreateDataGridV iewColumns()

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

'Assign DataSource to DataGridView
dgvInwDet.DataS ource = InwDetTbl

End Sub

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

For iCtr = 0 to 100
DataRow = InwDetTbl.NewRo w
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_CellB eginEdit(ByVal sender As Object, ByVal e As
System.Windows. Forms.DataGridV iewCellCancelEv entArgs) Handles
dgvInwDet.CellB eginEdit
Try
e.Cancel = Not IsEditable(e.Ro wIndex)
Catch ex As Exception
ErrorMessage()
End Try
End Sub

Priavate Function IsEditable(nRow No 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.C urrentCell.RowI ndex).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 3157
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.goo glegroups.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.EventArg s)
Handles MyBase.Load

'Configure DataGridView Style as Per Custome Requirement
ConfigerDataGri dViewStyle()

'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

CreateDataGridV iewColumns()

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

'Assign DataSource to DataGridView
dgvInwDet.DataS ource = InwDetTbl

End Sub

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

For iCtr = 0 to 100
DataRow = InwDetTbl.NewRo w
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_CellB eginEdit(ByVal sender As Object, ByVal e As
System.Windows. Forms.DataGridV iewCellCancelEv entArgs) Handles
dgvInwDet.CellB eginEdit
Try
e.Cancel = Not IsEditable(e.Ro wIndex)
Catch ex As Exception
ErrorMessage()
End Try
End Sub

Priavate Function IsEditable(nRow No 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.C urrentCell.RowI ndex).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
6945
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) { fDeleteRow = false; if (chx_DeleteFlag.Checked) {
8
34285
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 my data. (AutoGenerateColumns is true). The data is 2 columns of System.String cell. 4. If I assign the DataTable to DataGridView.DataSource, I get 4 columns. 2
1
1761
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 of columns I want to display. Of those 3 of them are integer columns, which needed to be translated into string by looking up on a reference table. How can I translate the integer values to string after the table is fetched and put in the
2
5413
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 needed was to create an input mask for a date field in one of my columns. Is there any way to modify/extend the datagridview to allow me to use an input mask control for one of my columns?
2
15529
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 = GetFinancesConnString(); string sqlSelect = "select CheckNbr, CheckDate, CheckAmt from Disbursements" ; SqlDataAdapter adapter = new SqlDataAdapter(sqlSelect, connectionString);
11
76206
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 else who got stumped like I did. It seems so simple... binding a DataGridView to a List<T>. These are the two general problems that I kept running into: (1) When the data in the list updated, the data on the screen did not update. (2) When I...
6
4409
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 (Multiselect=false) from DGV - to do that I tried this: DGV.ClearSelection() Cosmetically this appears to work but it appears that the DGV still stores the index value of the selected row. If the 1st row I click on after executing ClearSelection() is the row...
1
13738
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 inconsistent in the detection of a vertical scrollbar. This involves situations when less than the client area is needed to hold the small amount of data. The inconsistency is when adjusting the panel size within or just below the bottom row....
3
9683
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 cool little feature - it will not call DataTable.Rows.Add until after you leave the DataGridView row. This is cool because it lets your user edit the record as much as needed to get it into a valid state before actually adding it to the DataTable.
0
8641
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
9204
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
9060
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
8959
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
8914
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...
1
6557
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5897
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
4397
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...
2
2380
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.