|
 Thanks Dave,
It worked, below is my code:
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
<ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip)> _
Public Class ToolStripmyFontCombo
Inherits ToolStripControlHost
Public Sub New()
MyBase.New(New FontClass)
End Sub
End Class
Public Class FontClass
Inherits ComboBox
Dim wait As Boolean
Public Sub New()
Me.DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
Me.DropDownStyle = ComboBoxStyle.DropDownList
Me.Text = ""
Dim ff As FontFamily
Dim fc As New FontConverter
For Each ff In FontFamily.Families
Dim comboitem As New ComboBoxItem
If ff.IsStyleAvailable(FontStyle.Regular) Then
comboitem.Text = ff.Name
comboitem.Font = fc.ConvertFromString(ff.Name)
Me.Items.Add(comboitem)
End If
Next
End Sub
Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
e.DrawBackground()
e.DrawFocusRectangle()
Dim item As New ComboBoxItem
Dim bounds As New Rectangle
bounds = e.Bounds
Try
item = Me.Items(e.Index)
e.Graphics.DrawString(item.Text, item.Font, New SolidBrush(e.ForeColor), bounds.Left, bounds.Top)
Catch ex As Exception
If (e.Index <> -1) Then
e.Graphics.DrawString((e.Index).ToString(), e.Font, New SolidBrush(e.ForeColor), bounds.Left, bounds.Top)
Else
e.Graphics.DrawString(Text, e.Font, New SolidBrush(e.ForeColor), bounds.Left, bounds.Top)
End If
End Try
MyBase.OnDrawItem(e)
End Sub
Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
wait = False
MyBase.OnMouseLeave(e)
End Sub
Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
wait = False
MyBase.OnMouseUp(e)
End Sub
Protected Overrides Sub OnSelectedIndexChanged(ByVal e As System.EventArgs)
Try
If wait = False Then
Dim fc As New FontConverter
Me.Font = fc.ConvertFromString(Me.Text)
End If
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub
End Class
Public Class ComboBoxItem
Private ctext As String
Private cSelFont As Font
Property Text() As String
Get
Return ctext
End Get
Set(ByVal Value As String)
ctext = Value
End Set
End Property
Property Font() As Font
Get
Return cSelFont
End Get
Set(ByVal Value As Font)
cSelFont = Value
End Set
End Property
Public Overrides Function ToString() As String
Return ctext
End Function
End Class
But it gives me a warning:
Warning 1 Constructor on type 'System.Windows.Forms.ToolStripControlHost' not found. 0 0
|
|
|
|
|
Hello,
I connected two computers in LAN 1st having IP 192.168.1.1 and 2nd having IP 192.168.1.2 and i am having sql server management studio express 2005 installed on 1st computer now when i run exe from 192.168.1.2 it throughs an error like.
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
where as it runs perfetly on 1st computer.
my conection string is
Public DBConn As ADODB.Connection
DBConn.ConnectionString = "Provider=MSDATASHAPE; Data Provider=SQLOLEDB.1;Data Source=TOSHIBA\SQLEXPRESS; Initial Catalog=" & App.Path & "\AVON_AIR_Data.mdf; User ID=sa; Password=; Integrated Security=SSPI; Persist Security Info=False;"
DBConn.Open DBConn.ConnectionString
Please suggest
Thank you.
|
|
|
|
|
This is VB forum, please post this question in the Database forum.
|
|
|
|
|
It'll be logging in on your first computer using Windows Authentication. Has the sa-account been enabled? Does the second PC have the correct password?
Bastard Programmer from Hell
|
|
|
|
|
You cannot use a database file on the local machine when connecting to a remote SQL Server instance.
You have to switch to a non-user-instance config string and permanently attach the database file on the remote machine to the SQL Server instance on the remote machine. This is easiesst done using the SQL Server Management tool. Then you can change the Initial Catalog option in your connection string to the database name you assign on the SQL Server.
If you're going to be using Integrated Security, do not supply a username and password. If you have to supply a username and password, do not use Integrated Security. The two options are mutually exclusive.
|
|
|
|
|
Hello,
I changed my connection string to
DBConn.ConnectionString = "Provider=SQLNCLI;AttachDBFileName=" & App.Path & "\newdb.mdf;Database=newdb;User Instance=true;Trusted_connection=Yes;"
but it gives me run time error like
Invalid connection string attribute..
Can you please suggest which attribute is invalid.
Thank You.
modified on Sunday, July 31, 2011 12:28 PM
|
|
|
|
|
How many times have you asked this question?
You don't have a clue what you're doing, do you?
You haven't understood any of the things I said in my other post and know nothing of what's in the connection string. Your "second" attempt you posted contains none of the fixes I told you about and you're still trying to attach a remote instance of SQL Server to a local file, which will not work.
http://www.connectionstrings.com[^]
|
|
|
|
|
|
thatraja wrote: Looks like you have posted this question multiple times
And you still keep answering him each time?
|
|
|
|
|
No, only 2nd time
|
|
|
|
|
Can I use MS Windows theme as GUI in my project?
|
|
|
|
|
Why would you want to?
Better to have your own gui, much more professional.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
Hi,
I need to plot a graph(bar charts) on windows form using values from a closed excel sheet .. tried but unable to do so .. can someone plz help me with a small example of how to implement using Zedgraph or any other suitable package ..
Regards...
Gauti..
|
|
|
|
|
|
|
|
Hello All,
Could anyone please let me know, if we have any library or any easy going way, in order to work with USB2 flashdrive... All I need to do is detect a USB2 flash-drive, and then save a file in it.
I am looking for any driver, or library or any other way, So that I dont have to go deeper inside USB protocol.
I can use VB.NET or c# if necessary.
thanks in advance
Hrishi
|
|
|
|
|
Have you looked at this article[^]?
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Hello,
So I have some code to change the color of a cell on a datagridview.
If e.Value.ToString.Length > 0 Then<br />
e.CellStyle.BackColor = Color.Blue<br />
e.CellStyle.ForeColor = Color.White<br />
End If
Where is the best place to put this, cell formatting or cell painting. Or is there a better place?
Thanks!
Rudy
|
|
|
|
|
|
Cellformatting is where you want it.
You were close. Just add another line under your code to change the color:
e.FormattingApplied = True
|
|
|
|
|
Hello,
I am currently trying to sort on a GridView after it has been populated with records from a SQL Server Express database.
I click on a column to sort it and I get the following error:
"DataTable must be set prior to using DataView."
The entirety of my code is as follows:
<script runat="server" >
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
Dim sqlConn As New SqlConnection
Dim sqlCmd As New SqlClient.SqlCommand
Dim sqlReader As SqlDataReader
'If no values are supplied in the textbox, throw an error message.
If TextBox2.Text = "" Then
MsgBox("A centre code needs to be provided...")
End If
If TextBox2.Text <> "" Then
'Telling the system the location of the database.
sqlConn.ConnectionString = "server=ServerName;Initial Catalog=dbName;Trusted_Connection=yes"
'Here we are opening the connection to the database.
sqlConn.Open()
'This is to say that sqlCmd is a stored procedure.
sqlCmd.CommandType = System.Data.CommandType.StoredProcedure
'This is creating the command to execute the stored procedure based on the information given in the connection string.
sqlCmd = sqlConn.CreateCommand
'The command is triggered to execute the stored procedure which grabs all information for the specific centre.
sqlCmd.CommandText = "exec ProcedureName'" & TextBox2.Text & "' "
'This will read the rows in the database.
sqlReader = sqlCmd.ExecuteReader()
'If there are rows of data that match are criteria
If (sqlReader.HasRows) Then
'The rows of data are grabbed for the specific centre from the database using the data reader.
GridView2.DataSource = sqlReader
GridView2.DataBind()
Else
MsgBox("The centre code provided does not exist...")
End If
'This is closing the connection to the database once we have finished with it.
sqlConn.Close()
'This is to clear the list of items out of the GridView box.
End If
End Sub
Protected Sub gvSorting_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs)
Dim dtSortView As New DataTable
dtSortView = GridView2.DataSource
If dtSortView Is Nothing Then
Dim dvSortedView As New DataView(dtSortView)
dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection)
GridView2.DataSource = dvSortedView
GridView2.DataBind()
End If
End Sub
Public Function getSortDirectionString(ByVal SortDirection As SortDirection) As String
Dim newSortDirection As String = String.Empty
If (SortDirection = SortDirection.Ascending) Then
newSortDirection = "ASC"
Else
newSortDirection = "DESC"
'Return newSortDirection
End If
Return newSortDirection
End Function
</script>
If anybody can give me any hints and tips on why this is happening, I would be extremely grateful.
From my understanding its telling me that there is no records in the GridView to sort, but why?
Thanks in advance,
Dan
|
|
|
|
|
The problem is, you set the DataSource to a DataReader and trying to cast it back to a DataTable . Use a DataTable as the DataSource for the GridView and your code should work.
|
|
|
|
|
Instead of using, sqlReader = sqlCmd.ExecuteReader()
Use this:
Dim DA As SQLDataAdapter
DA = New SqlDataAdapter(SQLcmd)
DA.Fill(DT)
Gridview2.Datasource = DT
When you use a dataadapter to "Fill" a datatable, it will fetch all the rows into the datatable, so you must be careful that you are not fetching thousands of rows of data, your memory and performance will suffer tremendously.
With the above changes, your grid should sort when you click on a column heading.
david
|
|
|
|
|
Hello David,
Thank you very much.
Quick question though - what is DT?
Is that DataTable?
Thanks,
Dan
|
|
|
|