|
Hey all:
Is there any way in VB. Net to set background or foreground color whole column of datagrid?
-- modified at 0:14 Thursday 5th July, 2007
|
|
|
|
|
|
Hi,
I'm using VB.NET 2005 Express, and I'm having a go at teaching myself about threading as I want a marquee progress bar displayed on my form whilst it fills a table in a dataset.
On my form, I've got a textbox for a database name, and a textbox for simple Select SQL statements.
What I'm finding is that when I press 'Go', it populates the DataGridView perfectly, and my progress bar is displayed as I had wanted. However, what I then find is that if I change the contents of the database textbox, or the contents of the SQL textbox, and press 'Go' again, it either doesn't do anything to the DataGridView, or it completely falls over.
I'd really appreciate it if you could point me in the right direction to suggest some improvements to the very raw code shown below:
Imports System.Data<br />
Imports System.Data.OleDb<br />
<br />
Public Class Form1<br />
<br />
Private ds As New DataSet()<br />
Private conn As OleDb.OleDbConnection<br />
Private WithEvents backGroundWorker1 As New System.ComponentModel.BackgroundWorker<br />
<br />
' THREADING REFERENCES<br />
' http:
' http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1386086&SiteID=1<br />
<br />
Private Sub FillDataGridView()<br />
<br />
Dim strDataSource As String = Me.txtDataSource.Text & "@ol_server;"<br />
<br />
Dim strConnectionString As String = "Provider=Ifxoledbc.2;" & _<br />
"Password=informix;" & _<br />
"User ID=informix;" & _<br />
"Persist Security Info=True;" & _<br />
"Password=informix;" & _<br />
"Data Source=" & strDataSource.ToString<br />
<br />
conn = New OleDb.OleDbConnection(strConnectionString)<br />
<br />
Dim ds As New DataSet()<br />
<br />
backGroundWorker1.RunWorkerAsync()<br />
<br />
Dim i As Integer<br />
<br />
For i = 1 To 100<br />
<br />
Me.ProgressBar1.Value = i<br />
<br />
Next<br />
<br />
End Sub<br />
<br />
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click<br />
<br />
Me.ProgressBar1.Visible = True<br />
<br />
Me.ProgressBar1.Refresh()<br />
<br />
FillDataGridView()<br />
<br />
End Sub<br />
<br />
Private Sub backGroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles backGroundWorker1.DoWork<br />
<br />
Dim da As New OleDb.OleDbDataAdapter<br />
Dim cmd As New OleDb.OleDbCommand<br />
<br />
conn.Open()<br />
<br />
cmd.Connection = conn<br />
cmd.CommandText = Me.txtSQLStatement.Text<br />
<br />
da.SelectCommand = cmd<br />
<br />
da.Fill(ds, "Table")<br />
<br />
conn.Close()<br />
<br />
End Sub<br />
<br />
Private Sub backGroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles backGroundWorker1.RunWorkerCompleted<br />
<br />
Me.ProgressBar1.Value = 0<br />
Me.ProgressBar1.Visible = False<br />
Me.ProgressBar1.Refresh()<br />
<br />
DataGridView1.DataSource = ds<br />
DataGridView1.DataMember = "Table"<br />
<br />
End Sub<br />
End Class
|
|
|
|
|
What specific error are you getting when the app falls over?
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
When my app fills a table adapter with values, null values go in just fine. Doesn't matter what types the values are. But, in a separate operation, when I try to insert a row, I get null value exceptions, even for the values declared as NULLABLE. I guess I need to test each value by using .hasValue, but what I don't understand is why the fill works with no problem and the insert doesn't.
|
|
|
|
|
Hi Ken,
First of all, you probably mean that your app fills a DataSet with the use of an adapter.
Something like MyAdapter.Fill(MyDataset) . The DataSet aparently is set to ignore restraints, so the fill operation, which is basically nothing more than a read operation, works just fine. When you use your adapter's InsertStatement, you actually tell it to create new data in the source table (database). All therefore depends on the design of the table in your data source (database?), from its properties you can see which fields must receive a value.
Hope this helps,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Johan, thanks for your clear explanation. Based on what you have pointed out, looks like I need to look more closely at the settings of the Access database that I am using--Ken
|
|
|
|
|
Hi,
I have a problem:I want to find the width of a word document.
I need it for my project.
Is a way to find this?
thanks.
|
|
|
|
|
Please don't cross post. Are you doing this in C# or VB.NET ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi! All,
Please help me how to generate XML file in VB6 using a view from the database?
Thanks and Regards,
Virendra
|
|
|
|
|
I am developing ASP.NET Web Application using vb.net One of
the requriement of this application is ...when user submit
the Web Form....it should open the Word Templete and
insert the values into that templete...
Does anybody knows...How to Open and Writes into Word
Document Using ASP.NET and vb.net Directly...i am looking for
specific sample...
Thanks,
-- modified at 8:43 Wednesday 4th July, 2007
|
|
|
|
|
hello frnd,
do u want to open the already saved file if yes try the following
first add the COM reference, if you have word 2000 then add
microsoft word object library 9.0 and if you have word 2003 then do add microsoft word object library 11.0
and then code as,
imports word = microsoft.office.interop.word
dim objApp as new word.application
dim objDoc as new word.document
objDoc = objApp.documents.open("\\Address Of Blank Word File")
objdoc.visible = true
and after writing content to file the user close the file
By this code ; Already stored file open and displayed
AND If you want to open the new file then
dim objApp as new word.application
dim objDoc as new word.document
objDoc = objApp.documents.add("\\Address Of Blank Word File where u want to create")
objdoc.visible = true
in both the case the user must write and save the document
regards,
koolprasad2003
If the message is useful for U then please Rate This message...
Be a good listener...Because Opprtunity knoughts softly...N-Joy
|
|
|
|
|
Ours is a web application and we get the error....."Message filter indicates that the application is busy..."
Please help...we need this urgently
Thanks,
Suresh
|
|
|
|
|
have you tried what i told....
working with word automation is easy...
regards,
koolprasad2003
Be a good listener...Because Opprtunity knoughts softly...N-Joy
|
|
|
|
|
this is our code....
It works in a windows application but not in a web application....please try it out and help..
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(336, 176)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(576, 470)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Dim wrdApp As Word.Application
Dim wrdDoc As Word._Document
Private Sub InsertLines(ByVal LineNum As Integer)
Dim iCount As Integer
' Insert "LineNum" blank lines.
For iCount = 1 To LineNum
wrdApp.Selection.TypeParagraph()
Next iCount
End Sub
Private Sub FillRow(ByVal Doc As Word.Document, ByVal Row As Integer, _
ByVal Text1 As String, ByVal Text2 As String, _
ByVal Text3 As String, ByVal Text4 As String)
With Doc.Tables.Item(1)
' Insert the data in the specific cell.
.Cell(Row, 1).Range.InsertAfter(Text1)
.Cell(Row, 2).Range.InsertAfter(Text2)
.Cell(Row, 3).Range.InsertAfter(Text3)
.Cell(Row, 4).Range.InsertAfter(Text4)
End With
End Sub
Private Sub CreateMailMergeDataFile()
Dim wrdDataDoc As Word._Document
Dim iCount As Integer
' Create a data source at C:\DataDoc.doc containing the field data.
wrdDoc.MailMerge.CreateDataSource(Name:="C:\DataDoc.doc", _
HeaderRecord:="FirstName, LastName, Address, CityStateZip")
' Open the file to insert data.
wrdDataDoc = wrdApp.Documents.Open("C:\DataDoc.doc")
For iCount = 1 To 2
wrdDataDoc.Tables.Item(1).Rows.Add()
Next iCount
' Fill in the data.
FillRow(wrdDataDoc, 2, "Steve", "DeBroux", _
"4567 Main Street", "Buffalo, NY 98052")
FillRow(wrdDataDoc, 3, "Jan", "Miksovsky", _
"1234 5th Street", "Charlotte, NC 98765")
FillRow(wrdDataDoc, 4, "Brian", "Valentine", _
"12348 78th Street Apt. 214", "Lubbock, TX 25874")
' Save and close the file.
wrdDataDoc.Save()
wrdDataDoc.Close(False)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim wrdSelection As Word.Selection
Dim wrdMailMerge As Word.MailMerge
Dim wrdMergeFields As Word.MailMergeFields
Dim StrToAdd As String
' Create an instance of Word and make it visible.
wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
' Add a new document.
wrdDoc = wrdApp.Documents.Add()
wrdDoc.Select()
wrdSelection = wrdApp.Selection()
wrdMailMerge = wrdDoc.MailMerge()
' Create MailMerge Data file.
CreateMailMergeDataFile()
' Create a string and insert it in the document.
StrToAdd = "State University" & vbCr & _
"Electrical Engineering Department"
wrdSelection.ParagraphFormat.Alignment = _
Word.WdParagraphAlignment.wdAlignParagraphCenter
wrdSelection.TypeText(StrToAdd)
InsertLines(4)
' Insert merge data.
wrdSelection.ParagraphFormat.Alignment = _
Word.WdParagraphAlignment.wdAlignParagraphLeft
wrdMergeFields = wrdMailMerge.Fields()
wrdMergeFields.Add(wrdSelection.Range, "FirstName")
wrdSelection.TypeText(" ")
wrdMergeFields.Add(wrdSelection.Range, "LastName")
wrdSelection.TypeParagraph()
wrdMergeFields.Add(wrdSelection.Range, "Address")
wrdSelection.TypeParagraph()
wrdMergeFields.Add(wrdSelection.Range, "CityStateZip")
InsertLines(2)
' Right justify the line and insert a date field
' with the current date.
wrdSelection.ParagraphFormat.Alignment = _
Word.WdParagraphAlignment.wdAlignParagraphRight
wrdSelection.InsertDateTime( _
DateTimeFormat:="dddd, MMMM dd, yyyy", _
InsertAsField:=False)
InsertLines(2)
' Justify the rest of the document.
wrdSelection.ParagraphFormat.Alignment = _
Word.WdParagraphAlignment.wdAlignParagraphJustify
wrdSelection.TypeText("Dear ")
wrdMergeFields.Add(wrdSelection.Range, "FirstName")
wrdSelection.TypeText(",")
InsertLines(2)
' Create a string and insert it into the document.
StrToAdd = "Thank you for your recent request for next " & _
"semester's class schedule for the Electrical " & _
"Engineering Department. Enclosed with this " & _
"letter is a booklet containing all the classes " & _
"offered next semester at State University. " & _
"Several new classes will be offered in the " & _
"Electrical Engineering Department next semester. " & _
"These classes are listed below."
wrdSelection.TypeText(StrToAdd)
InsertLines(2)
' Insert a new table with 9 rows and 4 columns.
wrdDoc.Tables.Add(wrdSelection.Range, NumRows:=9, _
NumColumns:=4)
With wrdDoc.Tables.Item(1)
' Set the column widths.
.Columns.Item(1).SetWidth(51, Word.WdRulerStyle.wdAdjustNone)
.Columns.Item(2).SetWidth(170, Word.WdRulerStyle.wdAdjustNone)
.Columns.Item(3).SetWidth(100, Word.WdRulerStyle.wdAdjustNone)
.Columns.Item(4).SetWidth(111, Word.WdRulerStyle.wdAdjustNone)
' Set the shading on the first row to light gray.
.Rows.Item(1).Cells.Shading.BackgroundPatternColorIndex = _
Word.WdColorIndex.wdGray25
' Bold the first row.
.Rows.Item(1).Range.Bold = True
' Center the text in Cell (1,1).
.Cell(1, 1).Range.Paragraphs.Alignment = _
Word.WdParagraphAlignment.wdAlignParagraphCenter
' Fill each row of the table with data.
FillRow(wrdDoc, 1, "Class Number", "Class Name", "Class Time", _
"Instructor")
FillRow(wrdDoc, 2, "EE220", "Introduction to Electronics II", _
"1:00-2:00 M,W,F", "Dr. Jensen")
FillRow(wrdDoc, 3, "EE230", "Electromagnetic Field Theory I", _
"10:00-11:30 T,T", "Dr. Crump")
FillRow(wrdDoc, 4, "EE300", "Feedback Control Systems", _
"9:00-10:00 M,W,F", "Dr. Murdy")
FillRow(wrdDoc, 5, "EE325", "Advanced Digital Design", _
"9:00-10:30 T,T", "Dr. Alley")
FillRow(wrdDoc, 6, "EE350", "Advanced Communication Systems", _
"9:00-10:30 T,T", "Dr. Taylor")
FillRow(wrdDoc, 7, "EE400", "Advanced Microwave Theory", _
"1:00-2:30 T,T", "Dr. Lee")
FillRow(wrdDoc, 8, "EE450", "Plasma Theory", _
"1:00-2:00 M,W,F", "Dr. Davis")
FillRow(wrdDoc, 9, "EE500", "Principles of VLSI Design", _
"3:00-4:00 M,W,F", "Dr. Ellison")
End With
' Go to the end of the document.
wrdApp.Selection.GoTo(Word.WdGoToItem.wdGoToLine, _
Word.WdGoToDirection.wdGoToLast)
InsertLines(2)
' Create a string and insert it into the document.
StrToAdd = "For additional information regarding the " & _
"Department of Electrical Engineering, " & _
"you can visit our Web site at "
wrdSelection.TypeText(StrToAdd)
' Insert a hyperlink to the Web page.
wrdSelection.Hyperlinks.Add(Anchor:=wrdSelection.Range, _
Address:="http://www.ee.stateu.tld")
' Create a string and insert it in the document.
StrToAdd = ". Thank you for your interest in the classes " & _
"offered in the Department of Electrical " & _
"Engineering. If you have any other questions, " & _
"please feel free to give us a call at " & _
"555-1212." & vbCr & vbCr & _
"Sincerely," & vbCr & vbCr & _
"Kathryn M. Hinsch" & vbCr & _
"Department of Electrical Engineering" & vbCr
wrdSelection.TypeText(StrToAdd)
' Perform mail merge.
wrdMailMerge.Destination = _
Word.WdMailMergeDestination.wdSendToNewDocument
wrdMailMerge.Execute(False)
' Close the original form document.
wrdDoc.Saved = True
wrdDoc.Close(False)
' Release References.
wrdSelection = Nothing
wrdMailMerge = Nothing
wrdMergeFields = Nothing
wrdDoc = Nothing
wrdApp = Nothing
' Clean up temp file.
System.IO.File.Delete("C:\DataDoc.doc")
End Sub
End Class
|
|
|
|
|
Dear Suresh,
let me suggest U a simplest and finest way,
open a word file, record a macro and do the events u wants,
and stop the macro and Press Alt+F11
copy the code in VB Project and open that project using .Net it will gives you a code..
regards,
koolprasad2003
If the message is useful for U then please Rate This message...
Be a good listener...Because Opprtunity knoughts softly...N-Joy
|
|
|
|
|
i worked with macros also it's not working
can please help me. if u have code for creating word document.
Dim w As New Word.Application
Dim d As Word.Document
d = w.Documents.Open("c:\test1.doc")
'w.Selection.MoveRight(Unit:=1, count:=6)
d.MailMerge.OpenDataSource(Name:="C:\test1.csv", ReadOnly:=False, LinkToSource:=True, Connection:="", SQLStatement:="", SQLStatement1:="")
d.Fields.Add(Range:=w.Selection.Range, Type:=Word.WdFieldType.wdFieldMergeField, Text:="""LastName""")
With d.MailMerge
.Destination = Word.WdMailMergeDestination.wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = Word.WdMailMergeDefaultRecord.wdDefaultFirstRecord
.LastRecord = Word.WdMailMergeDefaultRecord.wdDefaultLastRecord
End With
.Execute(Pause:=False)
End With
w.Visible = True
|
|
|
|
|
hello guys
I have the following code:
Dim lineArray As String() = ProcessBuffer.ToString.Split(ControlChars.Cr)
Dim lineArrayList As ArrayList = ArrayList.Adapter(lineArray)
I use the Adapter method to convert my array to an arraylist, what is far more easy to work in my program.
Now when i want to remove a index I get this exception.
Unhandled Exception: System.NotSupportedException: Collection was of a fixed size.
at System.Array.System.Collections.IList.RemoveAt(Int32 index)
at System.Collections.IListWrapper.RemoveAt(Int32 index)
Anyone an idea how to avoid this problem without using a manual copy of all the elements into the arraylist. Because it seems that the arraylist gets a fixed size. :-/
|
|
|
|
|
try using the ArrayList(ICollection) constructor, that one copies the items for you.
|
|
|
|
|
Thanks for the answer.
I was checking ArrayList(ICollection) and I can't figure it out how it works, what i do, the same problem appears. Can you help me by putting me in the right direction?
Thanks.
|
|
|
|
|
Hi,
this is C# code that works; it prints 5 and 6
ArrayList list;
int[] arr=new int[]{1,2,3,4,5};
list=new ArrayList(arr);
log("count="+list.Count);
list.Add(6);
log("count="+list.Count);
If I am not mistaken, the crucial line translates to VB.NET as:
list=New ArrayList(arr)
|
|
|
|
|
Thanks that does the job. Now I can delete what I want without having problems.
|
|
|
|
|
Guys & Gals
i Was playing around with the screens .
Was wondering if i can use logo and have it revolving around the programs main form. How can i archive this?
|
|
|
|
|
Your question doesn't make a whole lot of sense. You can draw anything you like on your forms. Where do you want to draw it ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
think he want it to orbit around his form, passing in front and behind, maybe direct him to the graphics forum.
Posted by The ANZAC : "WWBD, What Would Buffy Do?" : "I don't know man, she's stronger than me"
|
|
|
|
|