|
This is less a VB.NET question, more SQL. I would suggest you post in the Database forum and show what statement you are using to select the records.
|
|
|
|
|
Hi have looked at previous answers on this blog which dont seem to help me.
I have a datagrid and add columns that are datagridtextboxcolumn . When I click on a cell on datagrid - if the line is too big for the width of cell , it will display on the following line, but when I am not clicked on the cell, the end of the line of text will not be displayed on the next line - and is therefore not displayed.
I derived a new class from datagridtextboxcolumn and attempted to override the paint and painttext methods and this appeared to have no effect - the text is displayed in the column and only 1 line is displayed.
My code is
Here is the derived class: -
( below I have overridden the paint and painttext class in order to see which method has some effect on the display in the datagrid - but there is no effect occuring through this process of overriding.
Imports Microsoft.VisualBasic
Imports System.ComponentModel
Imports System.Data
Imports System.Data.Common
Imports System.Data.OleDb
Imports System.Drawing
Imports System.Windows.Forms
Namespace DataGridRichTextBox
Public Class DataGridRichTextBoxColumn
Inherits DataGridTextBoxColumn
Private _source As CurrencyManager
Private _rowNum As Integer
Private _isEditing As Boolean
Public Sub New()
_source = Nothing
_isEditing = False
End Sub 'New
Protected Overloads Sub PaintText(ByRef g As Graphics, ByVal bounds As System.Drawing.Rectangle, ByRef Text As String, ByVal alligntoright As Boolean)
End Sub
Protected Overloads Sub PaintText(ByRef g As Graphics, ByVal bounds As System.Drawing.Rectangle, ByRef Text As String, ByRef s1 As System.Drawing.Brush, ByRef s2 As System.Drawing.Brush, ByVal alligntoright As Boolean)
End Sub
Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal _source As CurrencyManager, ByVal num As Integer)
End Sub
Protected Overloads Overrides Sub SetColumnValueatrow(ByVal _source As CurrencyManager, ByVal num As Integer, ByVal obj As Object)
End Sub
End Class 'DataGridComboBoxColumn
End Namespace
Here is where I add the derived class as an object to the datagrid : -
Imports System.Windows.Forms
Imports System.Data.SqlClient
Imports System.Drawing
Public Class DataGridMine
Inherits DataGrid
Public r_counter, column_num, x1 As Integer
Public x13 As Integer
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
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
Friend WithEvents SqlSelectCommand2 As New SqlCommand
Friend WithEvents DataSet51 As New tasks_trial2.DataSet5
Public WithEvents DataGridTableStyle1 As New DataGridTableStyle
Public WithEvents task_name_col, parent_col As New DataGridTextBoxColumn
Public WithEvents description_col As New DataGridRichTextBox.DataGridRichTextBoxColumn
Friend WithEvents SqlDataAdapter3 As New SqlDataAdapter
Friend WithEvents SqlDataAdapter2 As New SqlDataAdapter
Friend WithEvents SqlSelectCommand3 As New SqlCommand
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
CType(Priority_code_table1, System.ComponentModel.ISupportInitialize).BeginInit()
SuspendLayout()
Me.DataMember = "tasks"
Me.DataSource = DataSet51
Me.Location = New Point(8, 230)
Me.Size = New Size(1117, 384)
Me.TabIndex = 0
Me.TableStyles.AddRange(New DataGridTableStyle() {DataGridTableStyle1})
SqlDataAdapter2.SelectCommand = SqlSelectCommand2
SqlDataAdapter2.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "tasks")})
SqlSelectCommand2.CommandText = ""
SqlSelectCommand2.Connection = SqlConnection10
DataGridTableStyle1.DataGrid = Me
DataGridTableStyle1.AllowSorting = False
column_num = 3
DataGridTableStyle1.HeaderForeColor = SystemColors.ControlText
DataGridTableStyle1.MappingName = "tasks"
DataGridTableStyle1.SelectionBackColor = Color.Aquamarine
DataGridTableStyle1.SelectionForeColor = Color.Black
DataGridTableStyle1.PreferredRowHeight = 10
DataGridTableStyle1.PreferredColumnWidth = 75
description_col.HeaderText = "Description"
description_col.MappingName = "description"
description_col.Width = 260
.....................
' where column is description_col.
Public Sub add_columns(ByRef dgrid1 As DataGridMine, ByVal column As Object)
dgrid1.DataGridTableStyle1.GridColumnStyles.AddRange(New DataGridColumnStyle() {column})
End Sub
|
|
|
|
|
I am converting a VBA function to a VB .NET function. Here the VBA has an Oct() function for splitting a long into an array of x groups with 3 bytes. How can I create my own VB .NET function to do what the VBA Oct() does? Below is an example of how it is used:
'Create one long from this 3 bytes.
nGroup = &H10000 * Asc(Mid(inData, i, 1)) + _
&H100 * MyASC(Mid(inData, i + 1, 1)) + MyASC(Mid (inData, i + 2, 1))
'Oct splits the long To 8 groups with 3 bits
nGroup = Oct(nGroup)
Any help would be great!
Steve Holdorf
modified 28-Nov-14 11:24am.
|
|
|
|
|
lholdorf wrote: Oct splits the long To 8 groups with 3 bits That is 24 bits which does not make much sense. What value does the long hold, and what is the result of the Oct() function?
|
|
|
|
|
Your description of the Oct function appears to be wrong:
Returns a string representing the octal value of a number.
In VB.NET, you can either continue to use the Oct method[^], or you can use the Convert.ToString method[^], passing 8 as the base:
Dim octString As String = Convert.ToString(nGroup, 8)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I wrote a program for competition.
when I print at home I get a good result left on the Picture[^]
When I print at work. I have the result at the right site.
What do I wrong?
Here is the code.
Public Sub sPrnEmptyTabel(ByVal Personen As Int16, ByVal e As System.Drawing.Printing.PrintPageEventArgs, ByVal StartY As Int16)
Dim g As Graphics = e.Graphics
Dim nLijnLengte, nX As Integer
Dim n1CharX = g.MeasureString("A", Me.Font).Width
Dim n1CharY = Me.Font.Height
nLijnLengte = Personen * nAfstand + nNaamBreedte + 3 * nPuntBreedte + nVoorsprongBreedte
For nY As Integer = 1 To Personen
g.DrawLine(New Pen(Color.Black), 0, StartY + nNaamBreedte + (nY - 1) * nAfstand, nLijnLengte, StartY + nNaamBreedte + (nY - 1) * nAfstand)
g.DrawLine(New Pen(Color.Black), nNaamBreedte + (nY - 1) * nAfstand, StartY, nNaamBreedte + (nY - 1) * nAfstand, StartY + nNaamBreedte + (Personen) * nAfstand)
For nX = 1 To Personen
If nY = nX Then
g.FillRectangle(Brushes.Red, nNaamBreedte + nAfstand * (nX - 1), StartY + nNaamBreedte + (nY - 1) * nAfstand, nAfstand, nAfstand)
g.DrawString("*", New Font(Me.Font.Name, 20), Brushes.White, nNaamBreedte + nAfstand * (nX - 1), StartY + nNaamBreedte + (nY - 1) * nAfstand)
Else
Dim x1, x2, y1, y2 As Integer
x1 = nNaamBreedte + nAfstand * (nX - 1)
y1 = StartY + nNaamBreedte + (nY - 1) * nAfstand
x2 = x1 + nAfstand
y2 = y1 + nAfstand
g.DrawLine(Pens.Green, x2 - 5, y1 + 5, x1 + 5, y2 - 5)
End If
Next nX
g.DrawLine(New Pen(Color.Black), nNaamBreedte + (nY) * nAfstand, StartY, nNaamBreedte + (nY) * nAfstand, StartY + nNaamBreedte + (Personen) * nAfstand)
Next nY
g.DrawLine(New Pen(Color.Black), 0, StartY + nNaamBreedte + (Personen) * nAfstand, nLijnLengte, StartY + nNaamBreedte + Personen * nAfstand)
For n As Integer = 1 To 4
g.DrawLine(New Pen(Color.Black), nNaamBreedte + (Personen) * nAfstand + n * nPuntBreedte, StartY + 0, nNaamBreedte + (Personen) * nAfstand + n * nPuntBreedte, StartY + nNaamBreedte + (Personen) * nAfstand)
Next
With g
.TranslateTransform(0.0F, nNaamBreedte)
.RotateTransform(270)
Dim a As New List(Of String)
a.Add(LangSet.Table.tblWhite)
a.Add(LangSet.Table.tblBlack)
a.Add(LangSet.Table.tblGames)
a.Add(LangSet.Table.tblTotal)
For X As Integer = 0 To 3
Dim sKopTekst = " " & a(X)
g.DrawString(sKopTekst, New Font(Me.Font, FontStyle.Regular), Brushes.Black, -StartY, nNaamBreedte + (Personen + 3) * nAfstand + (X - 1) * nPuntBreedte)
Next
.RotateTransform(-270)
.TranslateTransform(0.0F, -nNaamBreedte)
sCopyRight(e, fGetResInfo("Titel1") & " " & fGetResInfo("Titel2"))
End With
End Sub
The code is called from a printdoc
Jan
|
|
|
|
|
|
It's also wrong on paper, not just on the screen.
On both systems it's paper is set to A4
i wroth a small test and size en resulutions are the same, A4 and 600X600
With e.Graphics
.DrawString("Papersize:", Me.Font, Brushes.Black, 50, 50)
.DrawString(PrintDocument1.DefaultPageSettings.PaperSize.ToString, Me.Font, Brushes.Black, 150, 50)
.DrawString("PaperSources:", Me.Font, Brushes.Black, 50, 100)
.DrawString(PrintDocument1.DefaultPageSettings.PaperSource.ToString, Me.Font, Brushes.Black, 150, 100)
.DrawString("PrinterResolutions:", Me.Font, Brushes.Black, 50, 150)
.DrawString(PrintDocument1.DefaultPageSettings.PrinterResolution.ToString, Me.Font, Brushes.Black, 150, 150)
End With
What else can I check
Jan
|
|
|
|
|
|
Hi,
I'm back. CreateMeasurementGraphics was no help. For me, I don't really need to check these things.
It was all my mistakes.
1. I forgot a variable in 1 of the 2 calculations. (Value on 1 system 50 and on another 42, diff 8)
2. I run a loop from 1 to 4 and must do from 0 to 3 (multiply with a value of 50)
3. That different of 8 was the reason some systems where ok and others not.
Even so thanks for the help.
Jan
|
|
|
|
|
I am a developer of Visual Basic, I was developing offline Software, Now I like to development a multi user application software , where database is store in online server. May be Ms Access or Mysql . I need the Concept and if i get source code it will be helpful
|
|
|
|
|
|
Do you understand how to work with a database on the same computer? If not, start with that.
Later, you need to understand a client-server-architecture. For communication between the two, look at e.g. WCF.
|
|
|
|
|
I'm underwater on this here. First time using vb to get JSON from a web service, actually I'm scraping it off a webpage.
This is my first attempt here, seems like it parsed, but I'm not able to figure out how to unpackage the object clean. I can see the obj in the web dev, and the data is key value paired.
Dim obj() As Object = New JavaScriptSerializer().Deserialize(Of Object)(pHTML)
sPR(idx).m_partNumber = obj(idx)(0).ToString
sPR(idx).m_shortDescription = obj(idx).Item("sItemName").ToString
I found this, but I can't find the instructions on how to use it.
https://gist.github.com/monk8800/3760559[^]
This is 1 record in a JSON array that I fetched from the web service
{
"sUrl": "/Itemdesc.asp?ic=CLK-WCP-1PK",
"sItemCode": "CLK-WCP-1PK",
"sItemName": "WaveCenter Wireless Port License",
"sItemImage": "CLK-WCP-1PK_50.jpg",
"sItemOrigImage": "CLK-WCP-1PK.jpg",
"sItemPrice": "$315.00",
"sRegularPrice": "$749.99",
"sItemStock": "7",
"bAllowSaleUnit": "F",
"sMeasureDesc": "EACH",
"sItemOrder": "Order"
},
I suspect that I need to use the List of T, like a type template. I can build one based on the array record above, just have no clue how to build one in vb.
Question:
I just need to get pointed in the right direction here.
|
|
|
|
|
jkirkerx wrote: I just need to get pointed in the right direction here. I'd assume that it simply needs a class with a public property for each entry. That way reflection could be used to fill in the values; that would not work if the list if made of objects, as there are no properties to map.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
You're very close - each item in the obj array will be a Dictionary(Of String, Object) , so you should be able to do:
Dim obj() As Object = New JavaScriptSerializer().Deserialize(Of Object())(pHTML)
sPR(idx).m_partNumber = obj(idx)("sItemCode").ToString()
sPR(idx).m_shortDescription = obj(idx)("sItemName").ToString()
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I woke up super early this morning, not enough sleep.
The error was from my structure not being dimensioned, SPR, so the right side could of been correct.
So I used JSON to Data Contract and made a class called dc_strekwave.
http://jsontodatacontract.azurewebsites.net/[^]
Then wrote this, I suppose I don't need the structure anymore, since the obj seems to do the trick now.
That was actually pretty easy in hindsight. very little code required once the class was made. Now I need to spit out a comma delimited file, and the prototype is done, and I can ship it today for approval.
Private Function parse_HTML_package_Store( _
ByVal pHTML As String) As Integer
Dim dwExitCode As Integer = 2
Dim sPR(0) As structure_product_records
Try
Dim obj As dc_streakwave() = New JavaScriptSerializer().Deserialize(Of dc_streakwave())(pHTML)
ReDim Preserve sPR(obj.Length - 1)
For idx As Integer = 0 To obj.Length - 1
sPR(idx) = New structure_product_records
sPR(idx).m_Url = obj(idx).sUrl
sPR(idx).m_ItemCode = obj(idx).sItemCode
sPR(idx).m_ItemName = obj(idx).sItemName
sPR(idx).m_ItemImage = obj(idx).sItemImage
sPR(idx).m_ItemOrigImage = obj(idx).sItemOrigImage
sPR(idx).m_ItemPrice = obj(idx).sItemPrice
sPR(idx).m_RegularPrice = obj(idx).sRegularPrice
sPR(idx).m_ItemStock = obj(idx).sItemStock
sPR(idx).m_AllowSaleUnit = obj(idx).bAllowSaleUnit
sPR(idx).m_MeasureDesc = obj(idx).sMeasureDesc
sPR(idx).m_ItemOrder = obj(idx).sItemOrder
Next
dwExitCode = 0
Catch ex As Exception
dwExitCode = 1
End Try
'Write the structure to a file
'Write the structure to a comma delimited file
Return dwExitCode
End Function
|
|
|
|
|
Hi
I'm having a problem in dragging and dropping multiple rows between datagrids. VB.Net can't do this by default, but i found a solution here: Drag drop multiple selected rows of datagridview with left mouse button[^]
I have put the code in a new class called DD_DataGridView.vb but I can't figure out how to use it.
I have a small test projekt, with 2 Datagridviews. Can anyone give me a hint on how to use the DD_DataGridView class from this projekt.
I'm dragging from DGV1 and dropping in DGV2.
SelectionMode is FullRowSelect
Public Class Form1
Dim DT1 As DataTable
Private rowIndexFromMouseDown As Int32
Dim MouseDwn As String
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
FillDataInGrids()
End Sub
Private Sub FillDataInGrids()
DT1 = New DataTable
'Table 1 has four columns
DT1.Columns.Add("Name", Type.GetType("System.String"))
DT1.Columns.Add("Designation", Type.GetType("System.String"))
DT1.Columns.Add("Department", Type.GetType("System.String"))
DT1.Columns.Add("Salary", Type.GetType("System.String"))
'Now Add some Rows in the first DataTable
Dim Dr As DataRow
For i = 1 To 40
Dr = DT1.NewRow
Dr("Name") = "Tom " & i.ToString("D3")
Dr("Designation") = "Developer " & i.ToString("D3")
Dr("Department") = "Engg " & i.ToString("D3")
Dr("Salary") = "100" & i.ToString("D3")
DT1.Rows.Add(Dr)
Next i
DGV2.Columns.Add("Name", "Name")
DGV2.Columns.Add("Designation", "Designation")
DGV2.Columns.Add("Department", "Department")
DGV2.Columns.Add("Salary", "Salary")
DGV2.Rows.Add(5)
'Now Bind the DataGrid to datatable 1
DGV1.DataSource = DT1
End Sub
Private Sub DGV1_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles DGV1.MouseDown
rowIndexFromMouseDown = DGV1.HitTest(e.X, e.Y).RowIndex
If rowIndexFromMouseDown <> -1 Then
If Control.MouseButtons = MouseButtons.Left Then
Dim hit As DataGridView.HitTestInfo = DGV1.HitTest(e.X, e.Y)
DGV1.DoDragDrop(DGV1.Rows(hit.RowIndex), DragDropEffects.Copy)
MouseDwn = DGV1.Name
End If
End If
End Sub
Private Sub DGV2_DragEnter(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles DGV2.DragEnter
e.Effect = DragDropEffects.Copy
End Sub
Private Sub DGV2_DragOver(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles DGV2.DragOver
e.Effect = DragDropEffects.Copy
End Sub
Private Sub DGV2_DragDrop(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles DGV2.DragDrop
Dim clientPoint As Point = DGV2.PointToClient(New Point(e.X, e.Y))
Dim hit As DataGridView.HitTestInfo = DGV2.HitTest(clientPoint.X, clientPoint.Y)
Dim myType As Type = GetType(DataGridViewRow)
Dim r As DataGridViewRow = DGV1.Rows(e.Data.GetData(myType).Index)
Dim i As Integer
If hit.RowIndex = -1 Then
i = DGV2.NewRowIndex
Else
i = hit.RowIndex
End If
DGV2.Rows.Insert(i)
For j As Integer = 0 To r.Cells.Count - 1
DGV2.Rows(i).Cells(j).Value = r.Cells(j).Value
Next
MouseDwn = ""
End Sub
End Class
I guess it's pretty simple, but I have to admit that I'm more a musician than a programmer
Regards, Tommy
|
|
|
|
|
You'd copy the code into a new class. Next you'd change the "DataGridView" control to a "DD_DataGridView". The easiest way would be by rebuilding, and checking if the new control is in the toolbox. The harder way involves modifying generated code.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you for answering. I forgot to tell that the 2 grids are of type DD_DataGridView.
I guess the problem is somewhere in my own code.
I can only copy one row, even when multiple rows are dragged
Regards, Tommy
|
|
|
|
|
That should have been the hardest part; if the code as is posted is correct, and nothing else changed, then the property "AllowMultiRowDrag" should only have to be set to "true", and it ought to work.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The problem seems to be that the MouseUp event never fires in DGV1.
If I comment this line out in DGV1_MouseDown, MouseUp fires but then I can't drag and drop.
DGV1.DoDragDrop(DGV1.Rows(hit.RowIndex), DragDropEffects.Copy)
The AllowMultiRowDrag should be set to true by the MouseUp event, if more rows are selected.
So basicly it's my own code that sucks
|
|
|
|
|
tommydk wrote: The AllowMultiRowDrag should be set to true by the MouseUp event Does it have to be allowed at the latest moment? Try setting it to true when the grid is constructed
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I finally gave up on this, and ended with this code.
Not elegant, but it works
I just pick up the selected rows in DGV1_DragLeave
Public Class Form1
Dim DT1 As DataTable
Private rowIndexFromMouseDown As Int32
Dim MouseDwn As String
Dim DragList As List(Of Integer)
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
FillDataInGrids()
End Sub
Private Sub FillDataInGrids()
DT1 = New DataTable
'Table 1 has four columns
DT1.Columns.Add("Name", Type.GetType("System.String"))
DT1.Columns.Add("Designation", Type.GetType("System.String"))
DT1.Columns.Add("Department", Type.GetType("System.String"))
DT1.Columns.Add("Salary", Type.GetType("System.String"))
'Now Add some Rows in the first DataTable
Dim Dr As DataRow
For i = 1 To 40
Dr = DT1.NewRow
Dr("Name") = "Tom " & i.ToString("D3")
Dr("Designation") = "Developer " & i.ToString("D3")
Dr("Department") = "Engg " & i.ToString("D3")
Dr("Salary") = "100" & i.ToString("D3")
DT1.Rows.Add(Dr)
Next i
'DGV2
DGV2.Columns.Add("Name", "Name")
DGV2.Columns.Add("Designation", "Designation")
DGV2.Columns.Add("Department", "Department")
DGV2.Columns.Add("Salary", "Salary")
DGV2.Rows.Add(5)
'Now Bind the DataGrid to datatable 1
DGV1.DataSource = DT1
End Sub
Private Sub DGV1_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles DGV1.MouseDown
rowIndexFromMouseDown = DGV1.HitTest(e.X, e.Y).RowIndex
If rowIndexFromMouseDown <> -1 Then
If Control.MouseButtons = MouseButtons.Left Then
Dim hit As DataGridView.HitTestInfo = DGV1.HitTest(e.X, e.Y)
DGV1.DoDragDrop(DGV1.Rows(hit.RowIndex), DragDropEffects.Copy)
MouseDwn = DGV1.Name
End If
End If
End Sub
Private Sub DGV1_DragLeave(sender As System.Object, e As System.EventArgs) Handles DGV1.DragLeave
DragList = New List(Of Integer)
For counter = 0 To (DGV1.SelectedCells.Count - 1)
If Not DragList.Contains(DGV1.SelectedCells(counter).RowIndex) Then DragList.Add(DGV1.SelectedCells(counter).RowIndex)
Next
End Sub
Private Sub DGV2_DragEnter(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles DGV2.DragEnter
e.Effect = DragDropEffects.Copy
End Sub
Private Sub DGV2_DragOver(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles DGV2.DragOver
e.Effect = DragDropEffects.Copy
End Sub
Private Sub DGV2_DragDrop(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles DGV2.DragDrop
Dim clientPoint As Point = DGV2.PointToClient(New Point(e.X, e.Y))
Dim hit As DataGridView.HitTestInfo = DGV2.HitTest(clientPoint.X, clientPoint.Y)
Dim i As Integer
If hit.RowIndex = -1 Then
i = DGV2.NewRowIndex
Else
i = hit.RowIndex
End If
DragList.Reverse()
For j As Integer = 0 To DragList.Count - 1
DGV2.Rows.Insert(i)
For c As Int32 = 0 To DGV1.Rows(j).Cells.Count - 1
DGV2.Rows(i).Cells(c).Value = DGV1.Rows(DragList.Item(j)).Cells(c).Value
Next
i = i + 1
Next
DragList.Clear()
MouseDwn = ""
End Sub
End Class
|
|
|
|
|