RE: Help: BindingManagerBase.Current() now working by v-kevy
v-kevy
Wed Nov 12 00:54:04 CST 2003
Hi Darwin,
Generally, when troubleshooting this kind of problem. We just set a break
point at the start of the prcedure and step through the codes, using the
watch window to monitoring the value of the variables. Would you please try
my way to debug it? Or if it still doesn't solve the problem, is it
convenient for you to send me the whole project? I'll try my best to help
you.
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
--------------------
| Content-Class: urn:content-classes:message
| From: <anonymous@discussions.microsoft.com>
| Sender: <anonymous@discussions.microsoft.com>
| References: <0cbc01c3a7f6$8496e1e0$a001280a@phx.gbl>
<qvkhfLDqDHA.444@cpmsftngxa06.phx.gbl>
| Subject: RE: Help: BindingManagerBase.Current() now working
| Date: Tue, 11 Nov 2003 08:53:57 -0800
| Lines: 127
| Message-ID: <013101c3a874$65d18b10$a301280a@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcOodGXPK3zxlmxBR6WvFi9eDzUcqw==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.framework.adonet
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:66019
| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| The exception message is:
| [System.NullReferenceException] {"Object reference not
| set to an instance of an object." }
|
| Here is the entire method:
|
| private void btnExcel_Click(object sender,
| System.EventArgs e)
| {
| excelApp = new Excel.ApplicationClass();
| wb = excelApp.Workbooks.Add(Type.Missing);
| BindingManagerBase bmClient = dgClient.BindingContext
| [dgClient.DataSource, "TClient"];
| for(int pos = 0; pos < bmClient.Count; pos++)
| {
| bmClient.Position = pos;
| dsBrowz2.TClientRow dr = bmClient.Current as
| dsBrowz2.TClientRow;
| Excel.Worksheet ws = wb.Worksheets.Add
| (Type.Missing,Type.Missing,Type.Missing,Type.Missing) as
| Excel.Worksheet;
| if (dr.clName.Length > 31)
| ws.Name = dr.clName.Substring(0, 31);
| else
| ws.Name = dr.clName;
| for(int col = 0; col <
| dsBrowz21.TVendor.Columns.Count; col++)
| {
| ws.Rows.Cells[0,col] =
| dsBrowz21.TVendor.Columns[col].Caption;
| }
| BindingManagerBase bmSupp= dgClSupp.BindingContext
| [dgClSupp.DataSource];
| for(int sPos = 0; sPos < bmSupp.Count; sPos++)
| {
| bmSupp.Position = sPos;
| DataRowView sdrv = bmSupp.Current as
| DataRowView;
| for(int sCol = 0; sCol <
| sdrv.Row.Table.Columns.Count; sCol++)
| {
| ws.Rows.Cells[sPos+1, sCol] = sdrv
| [sCol].ToString();
| }
| }
| }
| excelApp.Visible = true;
| }
|
| I have dr instances all throughout my code but they are
| all local variables and do not share scope with this
| instance of dr.
|
| Thanks,
| Darwin
|
| >-----Original Message-----
| >Hi Darwin,
| >
| >I think your code is right, please try to check if the
| dr has been defined
| >in ealier codes. And can you paste the whole exception
| here?
| >
| >If anything is unclear, please feel free to reply to the
| post.
| >
| >Kevin Yu
| >=======
| >"This posting is provided "AS IS" with no warranties,
| and confers no
| >rights."
| >
| >--------------------
| >| Content-Class: urn:content-classes:message
| >| From: "Darwin S." <dar@xmission.com>
| >| Sender: "Darwin S." <dar@xmission.com>
| >| Subject: Help: BindingManagerBase.Current() now working
| >| Date: Mon, 10 Nov 2003 17:52:52 -0800
| >| Lines: 25
| >| Message-ID: <0cbc01c3a7f6$8496e1e0$a001280a@phx.gbl>
| >| MIME-Version: 1.0
| >| Content-Type: text/plain;
| >| charset="iso-8859-1"
| >| Content-Transfer-Encoding: 7bit
| >| X-Newsreader: Microsoft CDO for Windows 2000
| >| X-MimeOLE: Produced By Microsoft MimeOLE
| V5.50.4910.0300
| >| Thread-Index: AcOn9oSWykA/ac4qQPakIWI7R2Q+7w==
| >| Newsgroups: microsoft.public.dotnet.framework.adonet
| >| Path: cpmsftngxa06.phx.gbl
| >| Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.framework.adonet:65970
| >| NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
| >| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
| >|
| >| Looking at this code from my application:
| >|
| >| BindingManagerBase bmClient = dgClient.BindingContext
| >| [dgClient.DataSource, "TClient"];
| >| for(int pos = 0; pos < bmClient.Count; pos++)
| >| {
| >| bmClient.Position = pos;
| >| dsBrowz2.TClientRow dr = bmClient.Current as
| >| dsBrowz2.TClientRow;
| >| if (dr.clName.Length > 31)
| >| ws.Name = dr.clName.Substring(0, 31);
| >| else
| >| ws.Name = dr.clName;
| >| }
| >|
| >| You can see that I set a BindingManagerBase object
| with a
| >| datagrid's (dgClient) BindingContext() method. Then
| >| inside the for loop I set a TClientRow object with the
| >| binding manager's Current property. That statement
| >| works. But then in the next line, the dr. object is
| >| throws an exception because dr is undefined. What am
| I
| >| doing wrong???
| >|
| >| Thanks,
| >| Darwin
| >|
| >
| >.
| >
|