dcsimg
Results 1 to 5 of 5

Thread: Not getting ID column listed in grid and throws error

  1. #1

    Thread Starter
    Member
    Join Date
    May 2018
    Posts
    41

    Not getting ID column listed in grid and throws error

    Hi ,

    I have error

    {"DataGridColumnStyle of 'ID' cannot be used because it is not associated with a Property or Column in the DataSource."}

    The Datagrid is sized with 5 columns but only 2 show up, and the value is throwing error when passing to form.
    I am trying to create a form when click on datagrid.


    Code:
       
    
    Private Sub cmdEditComplaints_Click(sender As Object, e As EventArgs) Handles cmdEditComplaint.Click
    
    		Dim iRow As Integer
    
    		If Not IsRowSelected(dgComplaints, dsComplaints.Tables(0).Rows.Count) Then Exit Sub
    
    			   		 	  
    		iRow = dgComplaints.CurrentRowIndex
    
    		miComplaint = dgComplaints.Item(iRow, 0).Value
    
    
    
    		Dim frm As New frmCaseComplaints
    		'If frm.LoadForm(miComplaint) Then
    		If frm.FormLoad_FromAgent(mRefno, False, dgConvictions.Item(dgConvictions.CurrentRowIndex, 0)) Then

    TIA

  2. #2
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,013

    Re: Not getting ID column listed in grid and throws error

    Your code make no sens to me. If you could be more specific as to what youre trying to do we could get you going on something proper.

  3. #3

    Thread Starter
    Member
    Join Date
    May 2018
    Posts
    41

    Re: Not getting ID column listed in grid and throws error

    I have datagrid on form that shows rows from a table, clicking on one of the rows opens the data behinbd in a new form.

    The Grid is setup below, but not working only showing 2 columns "ComplaintResolved" and "DateComplaintCreated".
    It has 4 columns including "ID" and "CreatedBy" which are not showing on grid.

    Code:
    Private Sub Size_ComplaintsGrid()
    
    		Dim dgts As DataGridTableStyle
    		Dim c As DataGridTextBoxColumn
    		Dim b As DataGridBoolColumn
    		dgts = New DataGridTableStyle
    		dgts.MappingName = "Table"
    
    
    		c = New DataGridTextBoxColumn
    		c.HeaderText = "ID"
    		c.MappingName = "PK_ComplaintID"
    		c.Width = 20
    		'c.Format = "0"
    		c.NullText = ""
    		c.Format = ""
    		c.Alignment = HorizontalAlignment.Left
    		dgts.GridColumnStyles.Add(c)
    
    		b = New DataGridBoolColumn
    		b.HeaderText = "ComplaintResolved"
    		b.MappingName = "ComplaintResolved"
    		b.Width = 20
    		b.Alignment = HorizontalAlignment.Center
    		dgts.GridColumnStyles.Add(b)
    
    
    		c = New DataGridTextBoxColumn
    		c.HeaderText = "Date Complaint Created"
    		c.MappingName = "DateComplaintCreated"
    		c.Width = 20
    		'c.Format = "0"
    		c.NullText = ""
    		c.Format = ""
    		c.Alignment = HorizontalAlignment.Left
    		dgts.GridColumnStyles.Add(c)
    
    
    
    		c = New DataGridTextBoxColumn
    		c.HeaderText = " Created By"
    		c.MappingName = "UserIDCreated"
    		c.Width = 20
    		'c.Format = "0"
    		c.NullText = ""
    		c.Format = ""
    		c.Alignment = HorizontalAlignment.Left
    		dgts.GridColumnStyles.Add(c)
    
    
    		dgComplaints.TableStyles.Clear()
    		dgComplaints.TableStyles.Add(dgts)
    		SizeColumnsV2(dgts, dgComplaints, 4)
    		dgComplaints.ReadOnly = True
    
    
    	End Sub



    Default Public Property Item(rowIndex As Integer, columnIndex As Integer) As Object

    The "Item" is being referenced by row and column , bu tthe column throws exception for ID.
    Last edited by SamCam15; Jan 29th, 2019 at 10:33 AM.

  4. #4
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,013

    Re: Not getting ID column listed in grid and throws error

    I cant quite say I smell what you're cooking there. TO me it looks like you can just use the designer to accomplish that menagerie. Oh wait, looking at it again, thats a Datagrid, not DataGridView.


    Is there a reason you're using Datagrid instead of DataGridView?

  5. #5

    Thread Starter
    Member
    Join Date
    May 2018
    Posts
    41

    Re: Not getting ID column listed in grid and throws error

    Quote Originally Posted by kpmc View Post
    I cant quite say I smell what you're cooking there. TO me it looks like you can just use the designer to accomplish that menagerie. Oh wait, looking at it again, thats a Datagrid, not DataGridView.


    Is there a reason you're using Datagrid instead of DataGridView?
    It is a DataGrid but a custom control, makes it difficult to set up right, but I've sorted it now. Only minor issue with the DataGrid seems to be, the last column doesn't fit the width, otherwise works as intended.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width