ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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?
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...
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?
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...
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.