LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-27-2005, 09:20 AM   #1
mrobertson
Member
 
Registered: May 2005
Posts: 275

Rep: Reputation: 30
vb.net error when trying to format data grid


I have the following code written in vb.net:
Code:
Dim coilpdi, allPLNcoils As String
Dim CoilPDIRowCount As Integer

Dim allcoils As New DataSet
Dim PDIDataset As New DataSet

Dim myConnection As New OracleConnection("Data Source=DUF_TCM; User ID=PCC;Password=DUFERCO")

myConnection.Open()

FileOpen(10, "C:\Documents and Settings\alogue\Desktop\Coil PDI\PDI.txt", OpenMode.Output)
PrintLine(10, txtgradecode.Text, txtwidth.Text, txthbgauge.Text, txttargetgauge.Text)
FileClose(10)

'Queries for the roll id and mate specified by the find textbox
allPLNcoils = "Select * from tcm_planned_coil where process_status ='PLN' order by schedule_number, sequence_number"
coilpdi = "Select * from tcm_planned_coil where process_status = 'PLN' and grade_code ='" + txtgradecode.Text + "' and width = '" + txtwidth.Text + "' and hot_band_gauge='" + txthbgauge.Text + "' and target_gauge='" + txttargetgauge.Text + "' order by schedule_number, sequence_number"

Dim PDICommand As New OracleCommand(coilpdi, myConnection)
Dim allPLNcoilsCommand As New OracleCommand(allPLNcoils, myConnection)

Dim PDIAdapter As New OracleDataAdapter(PDICommand)
Dim allPLNcoilsAdapter As New OracleDataAdapter(allPLNcoilsCommand)


'clears the dataset 
PDIDataset.Clear()
allcoils.Clear()

'using the command object, open a data adapter
PDIAdapter.SelectCommand = PDICommand
allPLNcoilsAdapter.SelectCommand = allPLNcoilsCommand

'Fills the data adapter with the dataset
allPLNcoilsAdapter.Fill(allcoils, "Table3")
PDIAdapter.Fill(PDIDataset, "Table2")

With Me.dgQueryResults
.DataSource = allcoils 'display the data in the datagrid
.NavigateTo(0, -1) 'expand the datagrid one level
.NavigateTo(0, "Table3") 'expand the datagrid down to the child level to show query results
.ParentRowsVisible = False
.AllowSorting = True
.AllowNavigation = True
.AllowDrop = False
.ColumnHeadersVisible = True
.PreferredColumnWidth = 200 'Set in pixels
.ParentRowsVisible = False
.TabStop = False
.Enabled = True
.Visible = True
.ReadOnly = True
.AlternatingBackColor = System.Drawing.Color.Bisque
End With

RowCount = allcoils.Tables("Table3").DefaultView.Count
CoilPDIRowCount = PDIDataset.Tables("Table2").Rows.Count
ColCount2 = allcoils.Tables("Table3").Columns.Count + 1

'****************************** Display Coil PDI in Hidden ListBox *************************
For f = 0 To CoilPDIRowCount - 1
For q = 0 To RowCount - 1
If dgQueryResults.Item(q, 0) = PDIDataset.Tables("Table2").Rows(f).Item("ID") Then
lstcoilpdi.Items.Add(q)
End If
Next
Next

' f = 0
'q = 0
'****************************** End Display CoilPDI in Hidden ListBox **********************

AddCellFormattingColumnStyles2(Me.dgQueryResults, New FormatCellEventHandler(AddressOf FormatGridCells)) ' This is a private Sub within this class.

PDIDataset.Dispose()
allcoils.Dispose()

myConnection.Close()

Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information)
Finally

End Try
End Sub
Private Sub AddCellFormattingColumnStyles2(ByVal grid As DataGrid, ByVal handler As FormatCellEventHandler)
Dim w As Integer
Dim dgt2 As DataGridTableStyle
dgt2 = New DataGridTableStyle
dgt2.MappingName = "Table3"
Dim gridCol2 As DataGridFormattableTextBoxcolumn

w = 0
Do While (w < ColCount2 - 1)

gridCol2 = New DataGridFormattableTextBoxcolumn(w)
gridCol2.MappingName = allcoils.Tables("Table3").Columns (w).ColumnName
gridCol2.HeaderText = allcoils.Tables("Table3").Columns(w).ColumnName
AddHandler gridCol2.SetCellFormat, handler
dgt2.GridColumnStyles.Add(gridCol2)
w = (w + 1)

Loop

grid.TableStyles.Clear()
grid.TableStyles.Add(dgt2)
End Sub

Private Sub FormatGridCells(ByVal sender As Object, ByVal e As DataGridFormatCellEventArgs)
'This sub is responsible for changing the background color of rows in the DataGrid.

If e.Column = 5 Then '% shape tolerance column (called SHAPE_BAND1)
e.BackBrush = Brushes.LightYellow
End If

If e.Column = 10 Then '% gauge tolerance column (called PER_BODY_TOL)
e.BackBrush = Brushes.LightYellow
End If
'*************************** Format matching coil PDI ***************************
For a = 0 To lstcoilpdi.Items.Count - 1

If e.Row = lstcoilpdi.Items.Item(a) Then
e.BackBrush = Brushes.Black
e.ForeBrush = Brushes.White
End If

Next
'*************************** End Format matching coil PDI **************************
a = 0
End Sub
I am continually getting an:

Object not set to instance of an object error

Does anyone see where the problem may be here?

Last edited by mrobertson; 07-27-2005 at 10:48 AM.
 
Old 07-27-2005, 09:45 AM   #2
pnellesen
Member
 
Registered: Oct 2004
Location: Missouri, USA
Distribution: Slackware 12.2, Xubuntu 9.10
Posts: 371

Rep: Reputation: 31
Which line are you getting the error on? (I didn't feel like diving in and trying to figure it out myself )
 
Old 07-27-2005, 10:00 AM   #3
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
I made the line that is throwing the error bold
 
Old 07-27-2005, 10:04 AM   #4
ewaltd
LQ Newbie
 
Registered: Jul 2005
Distribution: SuSE 9.3 Pro and FC3
Posts: 17

Rep: Reputation: 0
Or post the stack trace for the exception.
 
Old 07-27-2005, 10:08 AM   #5
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
I do not know how to post the stack trace but the line that is throwing the error is now in bold
 
Old 07-27-2005, 10:21 AM   #6
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
You are doing an allcoils.dispose, and then trying to access the Tables collection on it...
 
Old 07-27-2005, 10:31 AM   #7
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
Thank you very much for your help. I no longer get there error that I was getting before. I still have one slight problem however. The code that Is supposed to highlight the selected rows is now working. No rows are being highlighted. Do you know what the problem may be? I wiil now make that peice of code bold.
 
Old 07-27-2005, 10:33 AM   #8
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
My code is never getting into that Sub. How would I send it into that sub?
 
Old 07-27-2005, 10:39 AM   #9
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Sorry, but I haven't really worked with the DataGrid control much so I can't tell you for sure what the problem is. However, it does look odd that you are setting the color properties on the EventArgs object that is passed in. Usually the EventArgs objects just give you info about whatever event occured. I don't quite see how setting properties on the EventArgs is going to set the color of your rows.

Unless maybe this is some sort of "pre-event" call that lets you set the colors that will be sent to the control... Again, I haven't ever used the DataGrid control so I'm not familiar with how it works.
 
Old 07-27-2005, 10:41 AM   #10
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Quote:
Originally posted by mrobertson
My code is never getting into that Sub. How would I send it into that sub?
Are you sure that's not just an event that is called when you change formatting on the object via methods on the object?

Try catching the event for when the selection changes, and then use methods on the DataGrid object itself to try and format it...
 
Old 07-27-2005, 10:50 AM   #11
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
Take a look at the bolded line now. This is where I call my columnstyle events and set the address to the sub that is responsible for coloring. Does this help?
 
Old 07-27-2005, 11:05 AM   #12
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
I'm still not quite sure how that is supposed to work. It still looks to me like your FormatGridCells is an event in response to the grid cells being formatted externally, not a call in which you specify the format. But as I said, I'm not that familiar with the DataGrid object.

Also, my .Net experience has been purely C# and a little Managed C++. I've tried to avoid VB .Net like the plague. That being said, I'm not as familiar with how VB .Net does it's event handling routines.

It would also help a bit if there was some indentation in the code above. It's really tough to tell where the blocks are...
 
Old 07-27-2005, 11:55 AM   #13
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
I appreciate all of your help. I understand that what I am trying to do is hard for you to reason out. I will keep working at it. In the mean time, is it possible that you may be able to help me with another issue I am having?

http://www.linuxquestions.org/questi...90#post1768490
 
Old 07-27-2005, 01:56 PM   #14
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
I think I understand what you are trying to do, I'm just not sure you are going about it the right way. They way it appears you are trying to use an event callback seems to contradict the way events work for every other .Net control I've ever used...

It's like if you hooked in a MouseDown event and when you got the MouseEventArgs, you tried to change the mouse position by setting the e.X and e.Y properties. That just doesn't work. Those properties are there to tell you where it was clicked, not for you to set where the mouse is...
 
Old 07-27-2005, 04:24 PM   #15
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Are you using the System.Windows.Forms.DataGrid? If so, wouldn't it be easiest to just set the SelectionBackColor and/or SelectionForeColor properties?

I'm not even seeing sort of DataGridFormattableText object, though, so maybe I'm way off on what you are using... I'm also checking it out in C#, but I was under the impression that all the .Net controls were essentially the same across the .Net languages.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Painting the row of a data grid a color in VB.net mrobertson Programming 1 07-30-2005 04:22 PM
appending data to a data grid mrobertson Programming 1 07-28-2005 10:07 PM
appending data to a data grid VB.net mrobertson Programming 6 07-28-2005 08:57 AM
DSN: Data format error & relay=[127.0.0.1] [127.0.0.1] calmbomb Linux - Software 0 11-07-2004 03:24 PM
When playing RealAudio I get an Unknown data format error message Notbobdylan Linux - Newbie 0 01-19-2004 09:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration