Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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...

  • *Experts*
Posted

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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted (edited)

[PLAIN]Datagrid combobox [Resolved][/PLAIN]

 

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

 

  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

Edited by divil

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...