|
Hmmm ... Based on your suggestions, I am going to refactory my code.
|
|
|
|
|
Hello All,
I want to make a Label that I can drag and drop. At the same time when I drag the original label it will leave a copy of it self.
Example: When I drag Label1 it will leave another Label to its Original Position( Lets Name the New Label1 in Original Position as Label2),
Then I should also be able to drag Label2 and Leave another Label (Label3), I also want to drag Label1 and Label2 but it should not leave a copy.
Here is my code: I been able to do multiplication of Label and Dragging of Label but I cannot drag all Labels:
Public Class Form1
Dim cursorX, cursorY As Integer
Dim dragging As Boolean
Dim labelno As Integer = 1
Private Sub Control_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown
dragging = True
cursorX = e.X
cursorY = e.Y
Dim label2 As New Label
labelno += 1
label2.Location = New Point(Label1.Location.X, Label1.Location.Y)
label2.Name = "Label" + labelno.ToString
label2.Text = label2.Location.ToString
Me.Controls.Add(label2)
End Sub
Private Sub Control_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseUp
dragging = False
End Sub
Private Sub control_MouseMOve(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseMove
If dragging Then
Dim ctrl As Control = CType(sender, Control)
ctrl.Left = (ctrl.Left + e.X) - cursorX
ctrl.Top = (ctrl.Top + e.Y) - cursorY
ctrl.BringToFront()
End If
End Sub
If you have clarification please inform me.
Thanks
|
|
|
|
|
You don't put the dragging code for a Label in the Form. You create your own Label control and put the dragging code in there. That makes your Label reusable in any control that has a Controls collection, such as a Form or Panel or whatnot.
I wrote up an article to do this very thing about 7 years ago and it's still valid today. Read: Create your Own Runtime Movable Windows Forms Controls[^]
|
|
|
|
|
Hi,
I know my question is a bit old and many people asked about this.
I would like to tell you that, I searched my question in various forums and also google it but I did not find my exact answer.
Somewhere it is written "Multiple column combobox" and somewhere it is written "Autocomplete combobox". But I found nowhere about "Multiple column autocomplete combobox".
-----------------------------
| ARIZONA | \/ | <-- Autocomplete Combobox (Autocompletemode = Suggest)
---------------------------------------------------------
| ARIZONA | 16 | D16 |
| ALBAMA | 18 | A28 | <-- 3 Column Dropdown
| ALASKA | 12 | C34 |
---------------------------------------------------------
I just need the above type autocomplete combobox where the data comes from a mysql database table. And how to implement it in datagridview.
I tried it in a combobox.....
Private Sub LoadCombo()
Dim dcommand As New MySqlCommand
Dim dadapter As New MySqlDataAdapter
Dim stdata As New DataTable
qry = "SELECT * FROM statedetails"
Try
OpenConnection()
dcommand.Connection = conn
dcommand.CommandText = qry
dadapter.SelectCommand = dcommand
dadapter.Fill(stdata)
Dim dbreader As MySqlDataReader = dcommand.ExecuteReader
While dbreader.Read
For i = 0 To stdata.Rows.Count - 1
cmb.Items.Add(stdata.Rows(i).Item("State"))
cmb.Items.Add(stdata.Rows(i).Item("OfficeId"))
cmb.Items.Add(stdata.Rows(i).Item("CityId"))
Next
cmb.DisplayMember = "State"
cmb.ValueMember = "StateId"
End While
cmb.AutoCompleteMode = AutoCompleteMode.Suggest
cmb.AutoCompleteSource = AutoCompleteSource.CustomSource
Catch ex As Exception
MsgBox(ex.Message)
Finally
CloseConnection()
End Try
End Sub
but the result is
-----------------------
| ARIZONA | \/ | <-- Autocomplete Combobox (Autocompletemode = Suggest)
-----------------------
| ARIZONA |
|16 |
|D16 |
| ALBAMA |
|18 | <-- 1 Column Dropdown
|A28 |
| ALASKA |
|12 |
|C34 |
-----------------
.... and autocomplete not happening.
I also want to do that, if I select Arizona, the Datagridview nex t cell will populate data "16" ("OfficeId").
I found the link...
Flat-MultiColumn Combobox with Autocomplete[^]
but this is a bit complex to me.
My question is how should I implement it in a combobox and in datagridview combobox ?
Please help...
modified 24-Jul-13 1:56am.
|
|
|
|
|
Biplob Singha Shee wrote: My question is how should I implement it in a combobox and in datagridview combobox ? A datagridview doesn't come with autocomplete, and comboboxes aren't grids. Which column should it use for the autocomplete if the user starts typing away?
Biplob Singha Shee wrote: but this is a bit complex to me. Then it might be a better idea to slam a datagridview on a form, add a textbox on bottom, write your own "autocomplete" (just lookup the value of the textbox in the grids' datasource) and pop that up when (without borders) if the user presses the button.
Yes, might be a bit work, but the design would be simpeler and the time required to develop it might even be less than trying to figure out how to tame a combobox.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Very thanks... I am trying...
|
|
|
|
|
Hi,
I am using vb.net form Reportviewer control which is calling .RDLC file but I want to pass two parameter toDate and fromDate to the report. I tried many option but no luck yet. can anyone please help.... below is the code options I have used..
Imports Microsoft.Reporting.WinForms
Public Class frmGuestPassReport
Private Sub frmGuestPassReport_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'GuestPassDS.GuestPass_Transaction' table. You can move, or remove it, as needed.
Me.GuestPass_TransactionTableAdapter.Fill(Me.GuestPassDS.GuestPass_Transaction)
Me.ReportViewer1.RefreshReport()
Me.ReportViewer1.RefreshReport()
Me.ReportViewer1.RefreshReport()
End Sub
'Private Sub FillByToolStripButton_Click(sender As System.Object, e As System.EventArgs)
' Try
' Dim RP(1) As Microsoft.Reporting.WinForms.ReportParameter
' RP(0) = New Microsoft.Reporting.WinForms.ReportParameter("fromDate", "2013-07-17")
' RP(1) = New Microsoft.Reporting.WinForms.ReportParameter("toDate", "2013-07-18")
' Me.GuestPass_TransactionTableAdapter.FillBy(Me.elevateDataSet.GuestPass_Transaction, FromDateToolStripTextBox.Text, ToDateToolStripTextBox.Text)
' Me.ReportViewer1.LocalReport.SetParameters(RP)
' Me.ReportViewer1.RefreshReport()
' Catch ex As System.Exception
' System.Windows.Forms.MessageBox.Show(ex.Message)
' End Try
'End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs)
'Dim adapter As New GuestPassDSTableAdapters.GuestPass_TransactionTableAdapter()
'Dim table As New GuestPassDS.GuestPass_TransactionDataTable()
'adapter.FillBy(table, Format(CDate(dtFromDate.Text.Trim), "yyyy-MM-dd"), Format(CDate(dtToDate.Text.Trim), "yyyy-MM-dd"))
'Dim myNewSource As New ReportDataSource("dsGuestPass", CType(table, DataTable))
'Me.ReportViewer1.LocalReport.DataSources.Clear()
'Me.ReportViewer1.LocalReport.DataSources.Add(myNewSource)
'Me.ReportViewer1.LocalReport.Refresh()
'Me.ReportViewer1.RefreshReport()
Try
Dim adapter As New GuestPassDSTableAdapters.GuestPass_TransactionTableAdapter()
Dim table As New GuestPassDS.GuestPass_TransactionDataTable()
adapter.FillByDate(table, Format(CDate(fromDate.Text.Trim), "yyyy-MM-dd"), Format(CDate(toDate.Text.Trim), "yyyy-MM-dd"))
Dim pInfo As ReportParameterInfoCollection
Dim paramList As New Generic.List(Of ReportParameter)
Dim sfdate As String = Format(fromDate.Value, "yyyy-MM-dd")
paramList.Add(New ReportParameter("fromDate", sfdate, False))
Dim stdate As String = Format(toDate.Value, "yyyy-MM-dd")
paramList.Add(New ReportParameter("toDate", stdate, False))
ReportViewer1.LocalReport.SetParameters(paramList)
pInfo = ReportViewer1.LocalReport.GetParameters()
Me.ReportViewer1.RefreshReport()
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub Button1_Click_1(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Try
'Me.ReportViewer1.LocalReport.DataSources.Clear()
'Dim adapter As New GuestPassDSTableAdapters.GuestPass_TransactionTableAdapter()
'Dim table As New GuestPassDS.GuestPass_TransactionDataTable()
'adapter.FillByDate(table, Format(CDate(fromDate.Text.Trim), "yyyy-MM-dd"), Format(CDate(toDate.Text.Trim), "yyyy-MM-dd"))
'Dim myNewSource As New ReportDataSource("dsGuestPass", CType(table, DataTable))
'Me.ReportViewer1.LocalReport.DataSources.Add(myNewSource)
'Me.ReportViewer1.Show()
'Me.ReportViewer1.LocalReport.Refresh()
'Me.ReportViewer1.RefreshReport()
ReportViewer1.ProcessingMode = ProcessingMode.Local
ReportViewer1.LocalReport.ReportPath = "GuestPassTransaction.rdlc"
Dim adapter As New GuestPassDSTableAdapters.GuestPass_TransactionTableAdapter()
Dim table As New GuestPassDS.GuestPass_TransactionDataTable()
adapter.FillByDate(table, Format(CDate(fromDate.Text.Trim), "yyyy-MM-dd"), Format(CDate(toDate.Text.Trim), "yyyy-MM-dd"))
Dim pInfo As ReportParameterInfoCollection
Dim paramList As New Generic.List(Of ReportParameter)
Dim sfdate As String = Format(fromDate.Value, "yyyy-MM-dd")
paramList.Add(New ReportParameter("fromDate", sfdate, False))
Dim stdate As String = Format(toDate.Value, "yyyy-MM-dd")
paramList.Add(New ReportParameter("toDate", stdate, False))
ReportViewer1.LocalReport.SetParameters(paramList)
pInfo = ReportViewer1.LocalReport.GetParameters()
Me.ReportViewer1.RefreshReport()
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub
End Class
Thanks,
dfdff
|
|
|
|
|
When using an RDLC we get the data first and pass that to the report viewer along with the report. This is the code from an old winforms sample passing in the datatable and the name of the report file
public partial class frmViewer : Form
{
public frmViewer(string sReportFile, DataSet dsData)
{
InitializeComponent();
ReportFile = sReportFile;
ReportDataSet = dsData;
}
private string ReportFile { get; set; }
private DataSet ReportDataSet { get; set; }
private void Form1_Load(object sender, EventArgs e)
{
string sPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\Reports";
ReportDataSet.Tables[0].TableName = "dtReport";
ReportDataSet.DataSetName = "ReportData";
string RepResource = Path.Combine("D:\\Bin10\\Reports\\Reports\\Reports", ReportFile + ".rdlc");
repViewer.Reset();
repViewer.LocalReport.ReportEmbeddedResource = RepResource;
repViewer.LocalReport.DataSources.Add(new ReportDataSource("ReportData", ReportDataSet.Tables[0]));
this.repViewer.RefreshReport();
}
}
Note that you need to name the table the same as the datasource used when designing the report.
[edit] sorry the sample is in c# but I no longer use VB [/edit]
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi Thanks for replying..but my question was how to pass report parameter...
dfdff
|
|
|
|
|
Here is one way your could do it.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim params As New List(Of Global.Microsoft.Reporting.WinForms.ReportParameter)
For Each pi As Microsoft.Reporting.WinForms.ReportParameterInfo In ReportViewer1.LocalReport.GetParameters()
Dim values() As String = pi.Values.ToArray()
Select Case pi.Name
Case "FromDate"
SetParameterValue_0(values, Today.ToString())
Case "ToDate"
SetParameterValue_0(values, Today.AddDays(1.0#).ToString())
End Select
params.Add(New Microsoft.Reporting.WinForms.ReportParameter(pi.Name, values))
Next
ReportViewer1.LocalReport.SetParameters(params)
Me.ReportViewer1.RefreshReport()
End Sub
Private Sub SetParameterValue_0(ByRef values() As String, ByVal value As String)
If values.Length = 0 Then
values = New String() {value}
Else
values(0) = value
End If
End Sub
|
|
|
|
|
Is there a way in VB6 to output an Access 2000 report to pdf?
|
|
|
|
|
Now there is a mix of ancient tech. Presumably you are using VB6 as the UI and Access as the DB. You may be able to save the report to excel and then convert it to PDF from there.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Or just install a PDF printer and print it from Access.
|
|
|
|
|
Hi,
I'm using a streamreader and writer for editing an excel vbaproject.bin file.
However when I read and write the file I have some differences in the codepage I think.
look at the pictures for what I mean[^]
At the left it is OK. After writing it's no longer ok (at the right)
Can some tell me what I'm doing wrong?
the code for reading
Dim s As New StreamReader(fiTemp.FullName, System.Text.Encoding.ASCII)
Dim vba As String = s.ReadToEnd()
s.Close()
The code for writing:
Dim s1 As New StreamWriter(fiTemp.FullName, False, System.Text.Encoding.ASCII)
s1.Write(newvba)
s1.Close()
I also tried without encoding
Jan
|
|
|
|
|
What's the VBA code you're using to read/write the file.
From the pictures, it appears as though you're trying to read/write a binary file and your VB.NET code is treating it as a text file. There is no encoding on a binary file.
|
|
|
|
|
|
Hi,
I have a MySql table.
Table Name : Rate
Fields:
1. CurrentDate
(DataType : Date )
2. MaterialPrice
(DataType : DOUBLE(10,3) )
In above everyday I have to enter the MaterialPrice as it changes everyday.
I created a form for the above table
I want to do that when my MdiForm loads, it checks if the Current Date data is blank and if it has no records then it open the form associated with the table(Rate).
I tried...
Private Sub FormMdi_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim d As Date = Date.Today
qry = "SELECT * FROM Rate WHERE CurrentDate =" & d & ""
Try
OpenConnection()
Dim dbcommand As New MySqlCommand
dbcommand.Connection = conn
dbcommand.CommandText = qry
Dim dbread As MySqlDataReader = dbcommand.ExecuteReader
While (dbread.Read())
If dbread("CurrentDate") = "" Then
Dim f As New FormRate
f.Show()
f.Owner = Me
End If
End While
Catch ex As Exception
MsgBox(ex.Message)
Finally
CloseConnection()
End Try
End Sub
It not opening the form. While debugging it, I saw the control goes to
Finally
CloseConnection() directly from
While (dbread.Read()) but not firing
If dbread("CurrentDate") = "" Then
Dim f As New Rate
f.Show()
f.Owner = Me
End If and the formMdi opens.
My purpose not solved.
For your information, Table "Rate" is completely blank or has no records.
Please Help
modified 20-Jul-13 5:39am.
|
|
|
|
|
Sorry to disturb you...
I have got my solution...
|
|
|
|
|
Hi Everybody!
I've Problem when i click on label dlg.ShowDialog(), and here is my code
Private Sub LblCoCau_Err_Click(sender As System.Object, e As System.EventArgs) Handles LblCoCau_Err.Click
Dim newThread As New Thread(New ThreadStart(AddressOf ThreadMethod))
newThread.SetApartmentState(ApartmentState.STA)
newThread.Start()
End Sub
Private Shared Sub ThreadMethod()
Dim dlg As New OpenFileDialog()
dlg.ShowDialog()
MessageBox.Show(dlg.FileName)
End Sub
Error after click in lable lblCoCau_Err:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Please help me to resolve this issue. Thank's very much
|
|
|
|
|
Don't post a link to a screen-shot; use the "Copy exception detail to the clipboard" option and post the result.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Why are you creating a new thread just to show a dialog? Try it without and see what happens.
Use the best guess
|
|
|
|
|
You cannot create, show, nor touch in any way any UI items on anything other than the startup thread.
Creating a thread to show a modal dialog? That's completely pointless...
|
|
|
|
|
|
Okay so I'm very new to Encryption, I have done a lot of research via Google and I cannot find an answer to my questions, so either I'm totally not understanding this or .. okay I don't get it. Maybe someone here can help:
1. I need to generate a 256 bit Public / private key pair and store them for later use
2. I need to be able to encrypt using a stored private key
3. I need to be able to decrypt with a stored public key
(2 and 3) I was unable to find some example where keys are loaded from a file to be used, they all generated the keys new for each encryption.
And maybe someone can explain to me the way to encrypt and decrypt large files about 5 mb each with a loop, as the padding issue seems to have issues. Im trying to break up very lage files into 5mb chunks and encrypt them, then later decrypt them back into the whole file.
To me all this seems to be simple but I am at a loss when Googling this info as it all seems to derive their solutions with so many different providers and methods, and I just don't fully understand whats going on.
So the bottom like is : How can I create a Public/Private Key pair that is AES256 compliant (If that's even right) but I need a 256 bit PKI , then store them in a file to be used in the encrypt decrypt system. Can this be done without using a pass-phrase?
Again I have gotten to the point of encrypting with the use of some examples..
Here is my Generate keys function which works but im not sure if it is creating keys that I need (256)
<pre lang="vb">
Private Shared Sub Keys(publicKeyFileName As String, privateKeyFileName As String)
Dim cspParams As CspParameters = Nothing
Dim rsaProvider As RSACryptoServiceProvider = Nothing
Dim publicKeyFile As StreamWriter = Nothing
Dim privateKeyFile As StreamWriter = Nothing
Dim publicKey As String = ""
Dim privateKey As String = ""
Try
cspParams = New CspParameters()
cspParams.ProviderType = 1
cspParams.Flags = CspProviderFlags.UseArchivableKey
cspParams.KeyNumber = CInt(KeyNumber.Exchange)
rsaProvider = New RSACryptoServiceProvider(cspParams)
publicKey = rsaProvider.ToXmlString(False)
publicKeyFile = File.CreateText(publicKeyFileName)
publicKeyFile.Write(publicKey)
privateKey = rsaProvider.ToXmlString(True)
privateKeyFile = File.CreateText(privateKeyFileName)
privateKeyFile.Write(privateKey)
Catch ex As Exception
Console.WriteLine("Exception generating a new key pair! More info:")
Console.WriteLine(ex.Message)
Finally
' Do some clean up if needed
If publicKeyFile IsNot Nothing Then
publicKeyFile.Close()
End If
If privateKeyFile IsNot Nothing Then
privateKeyFile.Close()
End If
End Try
</pre>
Here is the encryption routine, again i have no idea how to have it use MY key and no password:
<pre lang="vb">
Dim rk As Byte() = Nothing
Dim riv As Byte() = Nothing
Dim salt As Byte() = System.Text.Encoding.ASCII.GetBytes("System.Text.Encoding.ASCII.GetBytes")
Dim pb As New PasswordDeriveBytes("somepassword", salt)
Dim origName As String = TmpStore & "\" & f.ToString
Dim encName As String = origName & ".enc"
cryptoKey = pb.GetBytes(32) : cryptoIV = pb.GetBytes(16)
Try
crm.EncryptData(origName, encName, cryptoKey, cryptoIV)
Dim fi As New FileInfo(origName) : Dim fi2 As New FileInfo(encName)
If (fi.Attributes And FileAttributes.[ReadOnly]) = FileAttributes.[ReadOnly] Then fi.Attributes = fi.Attributes And Not FileAttributes.[ReadOnly]
fi2.CreationTime = fi.CreationTime : fi2.LastWriteTime = fi.LastWriteTime
fi2.Attributes = FileAttributes.[ReadOnly] Or FileAttributes.Archive
File.Delete(origName)
Catch ex As CryptographicException
MessageBox.Show(ex.Message)
Catch ex As IOException
MessageBox.Show(ex.Message)
Catch ex As UnauthorizedAccessException
'i.e. readonly
MessageBox.Show(ex.Message)
End Try
</pre>
Any help is greatly appreciated. Sorry for my lack of understanding, but I am sort of under a deadline and I just cant seem to pull it off with the information out there.
|
|
|
|
|
|