|
If you think someone is just going to hand you code you're sorely mistaken.
The only code you're going to get is the code YOU write.
Now, if you have a question I suggest you describe the problem you're having, in detail, and we'll see what see can do.
|
|
|
|
|
i have a app and in this app have a class inherits from datagridview. basically i try to create a datagridview with specific properties and it will be generated automatically as a control of a panel. after program starts, datagridview is created and retrieves some data from database. so far everythings ok.
Public Class grid
Inherits DataGridView
Private _dgv As New DataGridView
Public Property Dgv
Set(value)
_dgv = value
End Set
Get
Return _dgv
End Get
End Property
Public Sub New()
End Sub
Public Sub New(panel As Panel)
_dgv.Name = "dgv"
_dgv.Parent = panel
_dgv.AllowUserToAddRows = False
_dgv.AllowUserToDeleteRows = False
_dgv.ReadOnly = True
_dgv.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
_dgv.Dock = DockStyle.Fill
_dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect
_dgv.DefaultCellStyle.SelectionBackColor = Color.LightGray
_dgv.DefaultCellStyle.SelectionForeColor = Color.Black
_dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
_dgv.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
End Sub
End Class
using panel.controls.add(grid) routine for loading datagridview to panel.
my question is after datagridview generated how to triger cellmousedoubleclick event?
using vb.net 2012.
thanks in advance.
|
|
|
|
|
You can call an event like a method, if you provide the correct arguments.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
hi,
I managed. Actually there were more than one problem in my app. This question was just a step 1. But i did it all. I would like to explain how i did it.
The exact thing that i expect from my app is a custom genereted dgw and its celldouble click event firing. after that event happens another form pops up with controls on it and those controls retrieves data from sql server db.
How i did it the codes are below. not good programming i guess. any suggestions?
Public Sub New(panel As Panel)
_dgv.Name = isim
_dgv.Parent = panel
_dgv.AllowUserToAddRows = False
_dgv.AllowUserToDeleteRows = False
_dgv.ReadOnly = True
_dgv.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
_dgv.Dock = DockStyle.Fill
_dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect
_dgv.DefaultCellStyle.SelectionBackColor = Color.LightGray
_dgv.DefaultCellStyle.SelectionForeColor = Color.Black
_dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
_dgv.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
AddHandler _dgv.CellDoubleClick, AddressOf dgvClick
End Sub
Public Sub dgvClick(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs)
Dim sql As New SQLAraclari
sql.DBDT = Nothing
If e.RowIndex = -1 Then
Return
End If
If isim = "Sifreler" Then
Try
UserID = Convert.ToInt32(Dgv.CurrentRow.Cells(0).Value)
MsgBox(userID.ToString)
Catch ex As Exception
MsgBox(e.ToString)
End Try
sql.SorguyuCalistir("SELECT tblPersoneller.PerID, PerAdi, PerSoyadi, PerKullaniciAdi, PerSifre FROM tblPersoneller JOIN tblPersonelSifreler ON tblPersoneller.PerID = tblPersonelSifreler.PerID WHERE tblPersonelSifreler.PerID = " & UserID & ";")
For Each r As DataRow In sql.DBDT.Rows
frmSifreGir.txtAdi.Text = r("PerAdi")
frmSifreGir.txtSoyadi.Text = r("PerSoyadi")
If String.IsNullOrEmpty(r.Item("PerKullaniciAdi").ToString) Then
frmSifreGir.txtKullaniciAdi.Text = ""
Else
frmSifreGir.txtKullaniciAdi.Text = r("PerKullaniciAdi")
End If
If String.IsNullOrEmpty(r.Item("PerSifre").ToString) Then
frmSifreGir.txtSifre.Text = ""
Else
frmSifreGir.txtSifre.Text = r("PerSifre")
End If
Next
If sql.HataVarmi(True) Then MsgBox(sql.Exception)
frmSifreGir.Show()
ElseIf isim = "Kayitlar" Then
Else
End If
End Sub
|
|
|
|
|
You're creating a new database-object and then checking the rowindex;
If e.RowIndex = -1 Then
Return
End If Would you not want to do that as the first thing in the event? If it is -1, you won't need the database anyway.
I'd also recommend using the IDbConnection/IDbCommand structures to query a database; it is more recognizable and easier to maintain.
..the way it is now, some of our members would blast you for leaving your code vulnerable against SQL-injection.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
thanks for your advice. I used parameters against sql injection.
|
|
|
|
|
You're welcome
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Dear All
I have a scenario like the folder contains some 7000 file. I have to take 1st 2000 file and 7-zip it then another 2000 files and so on...How can achieve this using vb script. Can any one assist me/
R.Sasikumar
|
|
|
|
|
There's an example on using VB-script to execute a command here[^]. Find the correct parameters for 7zip, and execute it.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello All,
How can i embed excel inside the web browser in vb .net please help me in this regard.
Thanks & Regards,
Sampath
|
|
|
|
|
You'll need Excel locally installed if you want to open stuff using it. What have you tried, and what is the problem exactly?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Message Closed
modified 16-Jan-17 6:15am.
|
|
|
|
|
You cannot deserialise that JSON data to a System.Object, you need to specify the type of object that will contain the data, i.e Customer . You may need to talk to whoever creates it to use a better type name for the customer data.
|
|
|
|
|
Hello Everyone,
Can you please advice on why I cant connect to excel file without saving it on my machine.
I tried using these to connection string but still got an error External table is not in the expected format.
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & path & ";Extended Properties=Excel 12.0;"
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path & ";Extended Properties=Excel 8.0;"
When I try to open and save as the spreadsheet I can successfully connect. The file is on FTP and will be downloaded by automation and get information. I cannot make it automatic if I need to open the excel file and save it.
The terminal I will deploy the program dont have office installed so I need to use a different tool to get data. Any suggestion appreciated thanks in advance.
- Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.
- Most of the problem in your life are due to two reasons: you act without thinking, or think without acting.
|
|
|
|
|
Because you cannot use it over an application protocol connection, like FTP or HTTP. That isn't supported and, frankly, is not a reliable connection.
The file MUST be on a drive letter or UNC path.
If the extension of the Excel file ends in .XLSX, you have to use the ACE engine. If it's .XLS you can use Jet.
|
|
|
|
|
I download the file first from FTP to local files then connect locally.
I tried this
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & path & ";Extended Properties=Excel 12.0;"
but still got the error.
When I open the file and saved locally then retry to use the above connection string, I can now connect.
- Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.
- Most of the problem in your life are due to two reasons: you act without thinking, or think without acting.
|
|
|
|
|
I'm confused. You never mentioned anything about any error message in your OP nor this post.
You also posted connection string making it appear as though you can't open a connection to the database.
So, what's the problem and what's the error message?
|
|
|
|
|
Ok so I have a spreadsheet which has a .xlsx extension and downloaded this on a FTP site. As I search in the internet you need to use this connection string for .xlsx files using ADODB.
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & path & ";Extended Properties=Excel 12.0;" But this gives error on conn.Open , this is the error External table is not in the expected format. .
When I manually open the spreadsheet on MS Office Excel then save it, I can successfully connect to said spreadsheet.
Note: On my machine I have office installed but on the machines where my program will be deployed don't so I need to use ADODB to read the contents.
- Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.
- Most of the problem in your life are due to two reasons: you act without thinking, or think without acting.
|
|
|
|
|
hansoctantan wrote: When I manually open the spreadsheet on MS Office Excel then save it, I can successfully connect to said spreadsheet. Excel, the application, is very, very forgiving in terms of which data it accepts; but sounds like the original file may already be in an invalid format.
In that case, ADODB will fail to read it, as it is not as forgiving as Excel. On the plusside, it is also not as big as the entire Excel-package.
Run your file through a validator, or unzip it and take a look at the contents.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Really appreciate your help but the excel file came from our client so I cannot put it in any site as a sample.
What do you mean by run it on a validator?
- Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.
- Most of the problem in your life are due to two reasons: you act without thinking, or think without acting.
|
|
|
|
|
To see if it is a valid zipped XML file. Excel even accepts CSV files with the wrong extension.
hansoctantan wrote: What do you mean by run it on a validator? Something like this[^]. If the file is not valid then the connection will not succeed, but it might still be "good enough" for Excel.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
An Excel .XLSX file is really a .ZIP file with a bunch of XML files in it. Open it in WinZip or 7ZIP and take a look around.
If it isn't a .ZIP file, it's not really a .XLSX file and cannot be opened by the ACE engine as your connection string has specified.
|
|
|
|
|
Wow didn't know this. Yeah I can open it on 7Zip.
- Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.
- Most of the problem in your life are due to two reasons: you act without thinking, or think without acting.
|
|
|
|
|
So I'm on the other end now. I seem to have a prefect string complete with line feeds, formatted to look great as HTML.
I have multiline set to true.
Scenario 1:
I write to RichTextBox.text and I get 1 line
Scenario 2:
I write to RichTextBox.Lines, in which I have 78 lines and I get 2 lines, Line1 with text and Line 2 empty.
Somethings bombing the control to load lines, but I can't figure out what it is.
This is my last try, I tried about 10 things
Private Sub Load_RTB(ByVal p As String)
Dim newLines() As String = p.Split(vbCrLf)
RichTextBox1.Multiline = True
For Each line As String In newLines
line = line.Replace(vbCrLf, "")
Next
RichTextBox1.Lines = newLines
End Sub
From the clipboad, I had to do this
Private Sub PasteAction(ByVal sender As Object, ByVal e As EventArgs)
If Clipboard.ContainsText(TextDataFormat.Rtf) Then
RichTextBox1.SelectedRtf = Clipboard.GetData(DataFormats.Rtf).ToString
ElseIf Clipboard.ContainsText(TextDataFormat.Html) Then
RichTextBox1.SelectedText = Clipboard.GetText(System.Windows.Forms.TextDataFormat.Html)
ElseIf Clipboard.ContainsText(TextDataFormat.Text) Then
RichTextBox1.SelectedText = Clipboard.GetData(DataFormats.Text.Replace("\n", "\r\n")).ToString
End If
End Sub
21st Century Globalism has become Socialism on a planetary scale, in which the unequal treaties of the past have come back into play.
|
|
|
|
|
jkirkerx wrote: Dim newLines() As String = p.Split(vbCrLf) This line cuts up your text into lines. There will not be a CRLF in those lines. If you want to make a "text" out of your lines, you'd join them with a CRLF.
Dim test As String = "1,2,3,4"
Dim items As String() = test.Split(",")
Dim result As String = String.Join(Environment.NewLine, items)
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|