Dinesh Kudale
Dinesh Kudale

Reputation: 38

DevExpress Gridcontrol shows empty column after adding repositoryItemLookUpEdit

I have created windows VB.Net application using 'Visual Studio Express 2015 for windows' with .Net Framework 4.6. In that I have used Devexpress 19.1.6.0 Gridcontrol on the form. I want to bind Student details to gridcontrol. In 'Name' column of gridview, I want to show combobox to select any Name to update particular cell.


For that purpose I have used repositoryItemLookUpEdit.


'Name' column must contain Name of sutdent. But when I will run the program, then 'Name' column shows empty cells. Why? How to overcome this issue?


Also If I will implement same program Without using repositoryItemLookUpEdit, then all column's correct data will get bind to the gridview and 'Name' column will also not showing empty.


Form1.vb

Imports System.Data.SqlClient

Public Class Form1
    Dim cn As SqlConnection = New SqlConnection("Data Source=PC161\SQLEXPRESS;Database=Student;Integrated Security=true")
    Dim da As New SqlDataAdapter

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        LoadGrid()
    End Sub

    Private Function FetchAllDetails() As DataTable
        Dim dt As New DataTable
        da = New SqlDataAdapter("select * from StudentInfo", cn)
        da.Fill(dt)
        Return dt
    End Function

    Private Function FetchIdName() As DataTable
        Dim dt As New DataTable
        da = New SqlDataAdapter("select ID, NAME from StudentInfo", cn)
        da.Fill(dt)
        Return dt
    End Function

    Private Sub LoadGrid()
        Try
            GridControl1.DataSource = FetchAllDetails()
            RepositoryItemLookUpEdit1.DataSource = FetchIdName()
            RepositoryItemLookUpEdit1.ValueMember = "ID"
            RepositoryItemLookUpEdit1.DisplayMember = "NAME"
            RepositoryItemLookUpEdit1.NullText = ""
            RepositoryItemLookUpEdit1.PopulateColumns()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Class

Output after running the project

Output window after click on cell

Form1 Design

Added columns after click on 'Run Design' option on Gridcontrol

'In-place Editor Repository' option to add RepositoryItemLookupEdit

Upvotes: 0

Views: 1529

Answers (1)

Brendon
Brendon

Reputation: 1259

The FieldName property for your GridControl's student name column (GridColumn2) is set to NAME. This is likely a string value containing the actual student name, which is why the cell is not blank when you are NOT using the RepositoryItemLookUpEdit.

To have the student name displayed when using RepositoryItemLookUpEdit you need to change the FieldName property of GridColumn2 to be the student ID value that you are using as the ValueMember of the RepositoryItemLookUpEdit.

In short, Change the GridColumn2.FieldName property value to "ID" and it will work.

Upvotes: 1

Related Questions