473,395 Members | 1,680 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,395 software developers and data experts.

Object Reference Not Set error

I am trying to insert a row to a specific location to a datagridview at bound
mode. For implementing this feature i am adding a new column to grid 's
dataview's table. Setting sort index. Then sort by using that new column. Then
remove that new column. It seems working fine.
I run following code for the first time without error. But if i run 2'nd time i
got Object Reference Not Set to an instance of an object error at line :
dr.Cells["SO"].Value = i + 1;

What is the reason ?
public bool InsertRow()
{
if (base.CurrentRow!=null)
{
int curRowIndex = base.CurrentCell.RowIndex ;
int curColIndex = base.CurrentCell.ColumnIndex ;

DataColumn dcSort = new DataColumn("SO",
System.Type.GetType("System.Int32"));
DataView dv =
((CurrencyManager)base.BindingContext[base.DataSource, base.DataMember]).List as
DataView;
dv.Table.Columns.Add(dcSort);
BindingManagerBase bm =base.BindingContext[base.DataSource,
base.DataMember];
DataRowView dvr = (DataRowView)bm.Current;
DataView dvn = dvr.DataView;
int i = -1;
foreach (DataGridViewRow dr in base.Rows )
{
i++;
if (i < curRowIndex + 1)
{
dr.Cells["SO"].Value = i + 1;
}
else
{
dr.Cells["SO"].Value = i + 2;
}
}

DataRow row = dv.Table.NewRow();
row["ID"] = System.Guid.NewGuid().ToString().ToUpper();
row["SO"] = curRowIndex + 2;
dv.Table.Rows.InsertAt(row, curRowIndex);
dv.Table.AcceptChanges();
ListSortDirection direction = ListSortDirection.Ascending;
DataGridViewColumn sortColumn = base.Columns["SO"];
base.Sort(sortColumn, direction);
base.Columns.Remove(sortColumn);
dv.Table.Columns.Remove(dcSort);

base.CurrentCell = base[curColIndex, curRowIndex + 1];
base.Refresh();
}
return true;
}

Jan 13 '06 #1
0 2090

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

Similar topics

2
by: Pkpatel | last post by:
Hi, I keep getting this error every time I try to load crystalreportviewer on a webform with a dataset. Here is the error: -------------------------------------------------------- Server...
7
by: kon george | last post by:
Can somebody assist. I build this code on a dev laptop and copied across the entire code to a Windows 2003 server with 1.1 framework. It is basic ASP.NE T that uses web service for SQL Server...
9
by: Keith Rowe | last post by:
Hello, I am trying to reference a Shockwave Flash Object on a vb code behind page in an ASP.NET project and I receive the following error: Guid should contain 32 digits with 4 dashes...
1
by: Martine | last post by:
Hi there! I have a problem with programmatically adding user controls to my mobile webforms. If I load my usercontrol programmatically (in the Page_Load), the object is instantiated, I have...
6
by: blash | last post by:
Can someone help me? I really don't have a clue. My company staff told me they often got such error: "Object reference not set to an instance of an object." when they are in search result page...
3
by: nemo | last post by:
Hi, My application works fine on the localhost but spits this error as soon as I put it on the server. I know this error occurs when an object has not been instantiated prior to a reference, but...
3
by: Adam | last post by:
We have a web site that uses .vb for the web pages and .cs for a class module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does work with .NET 1.1. When trying to access a page...
5
by: eBob.com | last post by:
I am trying to change some Structures to Classes. The Classes now look like this ... Public Class OneAttr Public AttrName As String Public Column As String Public Caption As String End Class...
7
by: Brett | last post by:
I'm not sure why I keep getting this error, "Object reference not set to an instance of an object". Private Function somefunction() as string Dim MyCurrentClass As New Class1 Try For i As...
2
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...

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.