Datagrid ?

ettropics

Newcomer
Joined
Feb 20, 2003
Messages
8
I have a working datagrid, pulling in information through a dataset.

However, I need to set up several queries to get the solution to be pulled into the datagrid (for each of the columns).
For instance: In column1 of the datagrid the query is:

SELECT tblLookupCodes.lookupCodeID, tblLookupCodes.lookupCode, tblLookupCodes.lookupCodeDescription, tblLookupCodes.lookupCodeCategory
FROM tblLookupCodes
WHERE (((tblLookupCodes.lookupCodeCategory)="Program Placement"))
ORDER BY tblLookupCodes.lookupCodeSortOrder, tblLookupCodes.lookupCode, tblLookupCodes.lookupCodeDescription;

column2 of datagrid is:

SELECT tblLookupCodes.lookupCodeID, tblLookupCodes.lookupCode, tblLookupCodes.lookupCodeDescription, tblLookupCodes.lookupCodeCategory, tblLookupCodes.lookupCodeDescription
FROM tblLookupCodes
WHERE (((tblLookupCodes.lookupCodeCategory)="DIS Code"))
ORDER BY tblLookupCodes.lookupCodeSortOrder, tblLookupCodes.lookupCode, tblLookupCodes.lookupCodeDescription;

It continues on in this way.

I also need to be able to have dropdown menus for selection in this datagrid.

As I am new to vb.net and programming in general, I am extremely persistent and am learning.

This one has got me and I need some help. So any help that anyone can offer will be greatly appreciated.

Thank you...

happy to be programming...
 
If I remember right, there are no built-in combobox controls for .NETs DataGrid, it only comes with textbox and checkbox. I know there are a number of free-b controls available (with source) and a number of professional controls for purchase that add this. I downloaded the code for a ComboBox control and changed it to use a DateEdit control as well - turned out pretty nice. I don't have the code anymore though, I think I archived it inthe recycle bin when building my new machine :(

-Nerseus
 
Datagrid combobox [Resolved]

Thank you for your reply...
You're right there are no built in controls for this on the datagrid. I did however, find this code and it looks promising... still testing

Visual Basic:
   Private DataGridTest As New DataGridTextBoxColumn()
    Private WithEvents Combo As New ComboBox()

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim DBTable As New DataTable("Control")
        Dim Str(2) As String
        Str(0) = "Name"
        Str(1) = "ControlCol"
        Str(2) = "Description"
        Dim i As Integer
        For i = i To 2
            Dim DBFD As New DataColumn(Str(i))
            DBFD.DefaultValue = ""
            DBFD.DataType = System.Type.GetType("System.String")

            DBTable.Columns.Add(DBFD)

        Next
        DBTable.TableName = "Control"

        DataGrid1.DataSource = DBTable


        i = 0
        For i = i To 4
            DBTable.LoadDataRow(Str, True) ';
            DataGrid1(i, 0) = "My Name is Casey"
            DataGrid1(i, 1) = "This is a Control Col and how"
            DataGrid1(i, 2) = "Some description"
        Next

        Dim dgdtblStyle As New DataGridTableStyle()
        dgdtblStyle.MappingName = "Control"

        dgdtblStyle.RowHeadersVisible = False ';
        dgdtblStyle.HeaderBackColor = Color.LightSteelBlue ';
        dgdtblStyle.AllowSorting = False ';
        dgdtblStyle.HeaderBackColor = Color.Navy ';//.FromArgb(8,36,107);
        dgdtblStyle.HeaderForeColor = Color.White ';
        dgdtblStyle.HeaderFont = New System.Drawing.Font("Microsoft Sans Serif", 9.0F, FontStyle.Bold, GraphicsUnit.Point, 0) ';
        dgdtblStyle.GridLineColor = Color.DarkGray ';
        dgdtblStyle.PreferredRowHeight = Combo.Height
        DataGrid1.BackgroundColor = Color.White ';


        Dim Data1 As New DataGridTextBoxColumn()
        Data1.MappingName = "Name"
        Data1.HeaderText = "Name"
        dgdtblStyle.GridColumnStyles.Add(Data1)

        DataTest.MappingName = "ControlCol"
        DataTest.HeaderText = "Control"
        AddHandler DataTest.TextBox.Enter, AddressOf testthis
        dgdtblStyle.GridColumnStyles.Add(DataTest)

        Dim Data2 As New DataGridTextBoxColumn()
        Data2.MappingName = "description"
        Data2.HeaderText = "Description"
        dgdtblStyle.GridColumnStyles.Add(Data2)

        DataGrid1.TableStyles.Clear()
        DataGrid1.TableStyles.Add(dgdtblStyle)

    End Sub

    Private Sub testthis(ByVal Sender As Object, ByVal e As EventArgs)
        Dim List As New ArrayList()
        List.Add(New ListValues("No 1", "1"))
        List.Add(New ListValues("No 2", "2"))
        List.Add(New ListValues("No 3", "3"))
        List.Add(New ListValues("No 4", "4"))
        List.Add(New ListValues("No 5", "5"))


        Combo.DataSource = List
        Combo.DisplayMember = "LongName"
        Combo.ValueMember = "ShortName"
        DataTest.Width = Combo.Width
        DataTest.TextBox.Controls.Add(Combo)
        Combo.BringToFront()
    End Sub

    Private Sub Combo_select(ByVal sender As Object, ByVal e As System.EventArgs) Handles Combo.SelectionChangeCommitted
        DataGrid1(DataGrid1.CurrentCell) = Combo.SelectedValue
    End Sub
End Class

Public Class ListValues

    Private myShortName As String
    Private myLongName As String

    Public Sub New(ByVal strlongName As String, ByVal strShortName As String)
        MyBase.New()
        Me.myShortName = strShortName
        Me.myLongName = strlongName
    End Sub

    Public ReadOnly Property ShortName() As String
        Get
            Return myShortName
        End Get
    End Property

    Public ReadOnly Property LongName() As String
        Get
            Return myLongName
        End Get
    End Property

    Public Overrides Function ToString() As String
        Return Me.ShortName & " - " & Me.LongName
    End Function

Thanks again
 
Last edited by a moderator:
Back
Top