|
Can I have a sample of the code please where Findcontrol does work for Usercontrol. Thanks.
==================
My further investigation showed that Findcontrol does not work for Usercontrol placed on a page which has a masterpage. Is it a bug?
modified 25-Jun-16 1:06am.
|
|
|
|
|
The only possible workaround for me at this stage is not to use masterpages.
|
|
|
|
|
As I can't tell clearly here where you are trying to call FindControl from, I would suggest that you aren't doing this from your MasterPage , so you might want to try Master.FindControl("Card0") to find this control on the master page.
This space for rent
|
|
|
|
|
I added a
DataGridViewCheckBoxColumn to My Data Grid
Dim DesChkBox As New DataGridViewCheckBoxColumn
DesChkBox.Name = "chbSelect"
DesChkBox.HeaderText = "Select"
DesChkBox.TrueValue = True
DesChkBox.FalseValue = False
grdView.Columns.Add(DesChkBox)
DesChkBox.Width = 50
grdView.ReadOnly = False
grdView.AutoGenerateColumns = False
grdView.RowHeadersWidth = 5
And through a procedure I want to check the Check Box programmatically.
Private Sub prcDefaultSelection()
Try
grdView.Rows(0).Cells(3).Value = True
Catch ex As Exception
MsgBox(Err.Description)
End Try
End Sub
The Check Box is not Checking. Please help me.
|
|
|
|
|
You already posted this in the C# forum. Please do not crosspost.
|
|
|
|
|
Assuming that you are not getting an error message... Quote: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
And assuming that your DataGridView already has 3 columns before you add the checkbox column (you have hard-coded the Checkbox column as being the 4th column, index = 3)...
And assuming that you are actually calling prcDefaultSelection() from somewhere ...
Then this code works.
|
|
|
|
|
Thank you for the response. Yes exactly, I have
3 columns before before the checkbox column.
The procedure prcDefaultSelection() executes well, but the checkbox doesn't get checked. Thats my issue.
Is their any custom events should I need to fire?
|
|
|
|
|
This is working fine for me - the checkbox is being checked. I'm trying this in Windows Forms - are you using a different platform?
|
|
|
|
|
No i m working on Framework 4.5 Plat form only. No working still.
|
|
|
|
|
So windows forms? Not WPF, not ASP?
|
|
|
|
|
Hello !
I have an application in vb.net 2013 , Entity Framework 6 and SQL server 200R2.
I' have finished the Program , but on the client computer , my program use a text based file called MyProg.exe.config , where are several lines .
But I don't like this text file because it's easily modifiable , and someone can change and the result may be a not working program.
Is there any way to not use ths file , and to save the data for example to a binary file that can be modified only from inside my program ?
The actual MyProg.exe.config has this contents :
="1.0"="utf-8"
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<system.diagnostics>
<sources>
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog" />
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter" />
</sharedListeners>
</system.diagnostics>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="MyEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=USER-PC;initial catalog=DB1;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="MyEntities2" connectionString="metadata=res://*/Model2.csdl|res://*/Model2.ssdl|res://*/Model2.msl;provider=System.Data.SqlClient;provider connection string="data source=User-PC;initial catalog=DB2;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="Object" />
</assemblyBinding>
</runtime>
</configuration>
|
|
|
|
|
No, not realy. All of the built in configuration stuff expects the file to be there and in the format it is now.
But first, the Program Files folder, and everything under it, is ReadOnly to normal users. If everyone has admin permissions to their machines (really stupid idea!) then all you're doing is trying to protect the customer from themselves and that's a battle you're never going to win.
You don't have to put everything about your app in the app.config file. You can put all kinds of settings in your application Resources. They will no longer be editable, but the problem is that not even you are going to be able to edit them. You'll have to deploy a new .EXE if you update the settings you put in Resources.
modified 18-Jun-16 8:46am.
|
|
|
|
|
Thank you !
Maybe you're right for all that you wrote.
But let's suppose that for different reasons ( let's not talking about the reasons) , I need to eliminate this text based file.
It seems strange that programs created with vb.net requires a text based file. It seems an old way to hold the program's configuration data.
At least , I want to eliminate the part that hold the connection data for SQl server and Entity framework , because I want to let users configure these settings inside my application for example I will create a form that let users configure this settings and save this to a binary file.
I'm talking about this part :
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="MyEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=USER-PC;initial catalog=DB1;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="MyEntities2" connectionString="metadata=res://*/Model2.csdl|res://*/Model2.ssdl|res://*/Model2.msl;provider=System.Data.SqlClient;provider connection string="data source=User-PC;initial catalog=DB2;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
|
|
|
|
|
It has nothing to do with VB.NET
An XML file is editable, human readable, and a binary format would require another application in order to edit it. This would just be extra work on your part and quite a bit more difficult to get right, not to mention a pain in the ass when the structure of the file changes to support new options. You'd have to update the editor to match it and your code would also have to support multiple versions of a binary file.
But, if you want the extra work, there's nothing stopping you from writing your own configuration provider.
Just forget the binary file. It's actually the old way of storing data!
You can create your own settings in a file and save that to the users or the computers public data. You do not have to store it in app.config. You're going to have to read up on the ConfigurationManager class. You can create your own config file, separate from app.config, and store it in either the users profile or in the public profile that is common to all users on the machine. You can then tell the ConfigurationManager to load that config to get more settings, like your connection strings.
|
|
|
|
|
|
I have 163 data and bind in stringbuilder and convert into pdf but show only 162 data last data not show in pdf.
Using sw As New StringWriter()
Using hw As New HtmlTextWriter(sw)
Dim datStartDate As Date = calStartDate.SelectedDate
Dim datEndDate As Date = calEndDate.SelectedDate
Dim blnVisitsOnly As Boolean = cbxVisitsOnly.Checked
Dim intLisintFileCount As Integer = 0
If datStartDate > datEndDate Then
lblTestStatus.Text = "The start date must occur before the end date, please enter a valid start date."
Exit Sub
End If
'Retrieve Listing Data
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("BrokerLLCConnectionString1").ConnectionString.ToString)
Dim cmd As New SqlCommand()
If blnVisitsOnly = True Then
cmd.CommandText = "SELECT DISTINCT t_Listing.Listing_ID, t_Listing.ListingName, l_NamePrefix.PrefixAbbrev, t_Individual.NameFirst, t_Individual.NameLast, ISNULL(t_Individual.Address, '') AS Address, ISNULL(t_Individual.City, '') AS City, t_Individual.State_ID, ISNULL(t_Individual.ZipCode, '') AS ZipCode, t_Business.BusinessName, l_Broker.NameFirstBroker + ' ' + l_Broker.NameLastBroker AS ListingAgent FROM t_Owner LEFT OUTER JOIN t_ListingVisit RIGHT OUTER JOIN t_Listing ON t_ListingVisit.Listing_ID = t_Listing.Listing_ID RIGHT OUTER JOIN t_Business ON t_Listing.Business_ID = t_Business.Business_ID ON t_Owner.Business_ID = t_Business.Business_ID RIGHT OUTER JOIN l_NamePrefix RIGHT OUTER JOIN t_Individual ON l_NamePrefix.NamePrefix_ID = t_Individual.NamePrefix_ID ON t_Owner.Individual_ID = t_Individual.Individual_ID LEFT OUTER JOIN l_Broker ON t_Individual.DesignatedBroker_ID = l_Broker.Broker_ID WHERE (t_Listing.Listing_ID <> '') AND (VisitDate >= '" & datStartDate & "' AND VisitDate <= '" & datEndDate & "')"
cmd.Connection = conn
Else
cmd.CommandText = "SELECT DISTINCT t_Listing.Listing_ID, t_Listing.ListingName, l_NamePrefix.PrefixAbbrev, t_Individual.NameFirst, t_Individual.NameLast, ISNULL(t_Individual.Address, '') AS Address, ISNULL(t_Individual.City, '') AS City, t_Individual.State_ID, ISNULL(t_Individual.ZipCode, '') AS ZipCode, t_Business.BusinessName, l_Broker.NameFirstBroker + ' ' + l_Broker.NameLastBroker AS ListingAgent FROM t_Owner LEFT OUTER JOIN t_ListingVisit RIGHT OUTER JOIN t_Listing ON t_ListingVisit.Listing_ID = t_Listing.Listing_ID RIGHT OUTER JOIN t_Business ON t_Listing.Business_ID = t_Business.Business_ID ON t_Owner.Business_ID = t_Business.Business_ID RIGHT OUTER JOIN l_NamePrefix RIGHT OUTER JOIN t_Individual ON l_NamePrefix.NamePrefix_ID = t_Individual.NamePrefix_ID ON t_Owner.Individual_ID = t_Individual.Individual_ID LEFT OUTER JOIN l_Broker ON t_Individual.DesignatedBroker_ID = l_Broker.Broker_ID WHERE (t_Listing.Listing_ID <> '')"
cmd.Connection = conn
End If
Dim dr As SqlDataReader = Nothing
conn.Open()
dr = cmd.ExecuteReader()
Dim DT As New DataTable()
DT.Load(dr)
Dim sb As New StringBuilder()
sb.Append("<html xmlns='http://www.w3.org/1999/xhtml'>")
sb.Append("<head>")
sb.Append("</head>")
sb.Append("<body style=""font-family: Arial; color: #000000; font-size: medium;"">")
'sb.Append("")
sb.Append("")
'Dim k As Integer = 0
For i As Integer = 0 To DT.Rows.Count - 1
'k += 1
If i = 0 OrElse i Mod 3 = 0 OrElse i = DT.Rows.Count - 1 Then
sb.Append("")
' If i > 0 Then
' Else
' End If
'Else
End If
sb.Append("")
If i Mod 3 = 2 OrElse i = DT.Rows.Count - 1 Then
sb.Append(" ")
sb.Append("")
'k += 1
'If k = 10 Then
' Continue For
'End If
End If
'If (i Mod 3) = 0 AndAlso i > 0 Then
' sb.Append(" ")
' sb.Append("")
'End If
Next
sb.Append(" ")
sb.Append("")
sb.Append("")
sb.Append("")
sb.Append("")
sb.Append("")
sb.Append("")
sb.Append(DT.Rows(i)("PrefixAbbrev").ToString() + " " + DT.Rows(i)("NameFirst").ToString() + " " + DT.Rows(i)("NameLast").ToString())
sb.Append(" ")
sb.Append("")
sb.Append(If(Convert.ToString(DT.Rows(i)("Address").ToString()), If("", "", Convert.ToString(DT.Rows(i)("Address").ToString()))))
sb.Append(" ")
sb.Append("")
sb.Append(If(Convert.ToString(DT.Rows(i)("City").ToString()), If("", "", Convert.ToString(DT.Rows(i)("City").ToString()))))
sb.Append(", ")
sb.Append(If(Convert.ToString(DT.Rows(i)("State_ID").ToString()), If("", "", Convert.ToString(DT.Rows(i)("State_ID").ToString()))))
sb.Append(", ")
sb.Append(If(Convert.ToString(DT.Rows(i)("ZipCode").ToString()), If("", "", Convert.ToString(DT.Rows(i)("ZipCode").ToString()))))
sb.Append(" ")
sb.Append(" | ")
sb.Append(" |
")
'sb.Append(" ")
sb.Append("</body>")
sb.Append("</html>")
Dim sr As New StringReader(sb.ToString())
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=ExportedClientDocument.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim pdfDoc As New Document(PageSize.A4, 10, 5, 30, 50)
Dim htmlparser As New HTMLWorker(pdfDoc)
Dim pdfWriter__1 As PdfWriter = PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
htmlparser.Parse(sr)
pdfDoc.Close()
Response.Write(pdfDoc)
End Using
End Using
End Sub
modified 17-Jun-16 5:25am.
|
|
|
|
|
|
I have two gridview dgvsource and dgvtarget.dgvsource have filled data through datasource below is my code to fill.
Private Sub populate_dgv()
Dim conn As New SqlConnection
Dim cmd As New SqlCommand
conn = GetConnect()
conn.Open()
cmd.Connection = conn
Try
cmd.CommandText = "select Request_id,Request_date,Requestor,Destination,Department from tbeRequest r where r.request_id not in(select a.request_id from tbAssign_vehicle a)"
Dim Adpt As New SqlDataAdapter(cmd.CommandText, conn)
Dim ds As New DataSet()
Adpt.Fill(ds, "tbeRequest")
dgvsource.DataSource = ds.Tables("tbeRequest")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
1st gridview data is populated sucessfully.Then i have to copy selected row from 1st gridview to another gridview .Below is my code:
Private Sub dgvsource_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvsource.CellDoubleClick
Try
Dim i As Integer = 0
Dim Mylist As New List(Of Integer)
For Each row As DataGridViewRow In dgvsource.SelectedRows
Mylist.Add(row.Index)
Next
Mylist.Sort()
For Each index As Integer In Mylist
dgvtarget.Rows(i).Cells("request_id").Value = dgvsource.Rows(index).Cells("request_id").Value
i = i + 1
Next
Catch ex As Exception
End Try
End Sub
kindly help on this.
modified 17-Jun-16 4:20am.
|
|
|
|
|
i've this application that reads multiple files from a folder and upload them to the server..it works fine but when it wants to upload each file, it creates a connection, upload the file and closes the connection. it does the same thing for all the files over and over again. i want a situation where it creates just one connection, upload all the files and close the connection. please any help will be appreciated, i searched everywhere but couldnt find any help. below is my code
Imports System.IO
Imports System.Net
Public Class DemoFTPServerApp
Dim _Filename As String
Dim _UploadPath As String
Dim f As String
Public Sub LoadFiles(_User As String, _Password As String, _Path As String)
Dim _MyArraylist As New ArrayList
Dim FolderPath As String = "C:\Users\Desktop\files"
Dim finfo As New DirectoryInfo(FolderPath)
For Each fi In finfo.GetFiles("*.txt")
_MyArraylist.Add(fi.FullName) 'full path only
_Filename = fi.FullName
f = fi.ToString()
_UploadPath = _Path & f
Try
Dim request As FtpWebRequest = DirectCast(WebRequest.Create(New Uri(_UploadPath)), FtpWebRequest)
request.Method = WebRequestMethods.Ftp.UploadFile
request.Credentials = New NetworkCredential(_User, _Password)
request.UseBinary = True
request.UsePassive = False
request.KeepAlive = True
request.ConnectionGroupName = "company name"
request.ServicePoint.ConnectionLimit = 4
request.ServicePoint.CloseConnectionGroup("company name")
Dim buffer(1023) As Byte
Dim bytesIn As Long = 1
Dim filepath As System.IO.FileInfo = New System.IO.FileInfo(_Filename)
Dim _FileStream As System.IO.FileStream = filepath.OpenRead()
Dim _Stream As System.IO.Stream = request.GetRequestStream
Do Until bytesIn < 1
bytesIn = _FileStream.Read(buffer, 0, 1024)
If bytesIn > 0 Then
_Stream.Write(buffer, 0, bytesIn)
End If
Loop
_Stream.Close()
_Stream.Dispose()
_FileStream.Close()
_FileStream.Dispose()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Next
MessageBox.Show("File Succesfully uploaded!")
End Sub
Private Sub btnUploadFile_Click(sender As Object, e As EventArgs) Handles btnUploadFile.Click
LoadFiles("username", "password", "ftp://ftpsite.com/")
End Sub
|
|
|
|
|
Hello !
In a vb.net program that use a sql server database , is there a way to keep the database file in Program's folder instead of default sql server's Data folder ?
Thank you !
|
|
|
|
|
Yes, but the Program Folder is not meant for data, it is meant for applications. Data goes in the users' documents folder.
It may require administrative rights to make modifications in the Program Folder; meaning that any user using it would have to run in an administrative role.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
My program folder is something like this : c:\MyProgram1.
And let's says that there's no problem about permissions.
What else should I do to realize that scenario ?
|
|
|
|
|
Depends on your client; in my case you'd need at least bribe the sysadmin, otherwise there will not be a folder in the root of the drive. Also, data is "expected" to be in the documents folder for both backup-applications as well as migrations.
If you "create database", you have multiple options on where to store you datafiles and how large they are allowed to become. More info on MSDN[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Everying under Program Files is read-only to to normal users. It's not a good idea to put your database in there.
|
|
|
|
|
My program folder is something like this : c:\MyProgram1.
And let's says that there's no problem about permissions.
What else should I do to realize that scenario ?
|
|
|
|
|