Nuno
Nuno

Reputation: 126

DataGridView data

I have this class:

public class mobileSimple
{
    public DataGridView mobileData { get; set; }

    public DataGridView getMobileData()
    {
        return this.mobileData;
    }

    public void addMobileData(DataTable dt)
    {
        if (mobileData == null)
        {
            this.mobileData = new DataGridView();
        }
        this.mobileData.DataSource = dt;
    }
}

And I have this method in a form:

private void getMobileData2()
{
    mobileSimple mobile = null;

    string query = mobileQueryProvider.getMobileSimple();

    sqlConnect connect = new sqlConnect();
    DataTable mobileSimpleDataTable = connect.getBD(query);

    if (mobileSimpleDataTable.Rows.Count > 0)
    {
        mobile = new mobileSimple();
        mobile.addMobileData(mobileSimpleDataTable);
    }
    gvMobile.DataSource = mobile.getMobileData();
}

Can someone please explain me what am I doing wrong please? The DataGridView should be filled... I have tested the query and I am getting 2 rows.

Thank you.

Upvotes: 0

Views: 133

Answers (1)

Nuno
Nuno

Reputation: 126

A little bit more of research and I found the answer.

At the end of the method:

gvMobile.DataSource = mobile.getMobileData();

I was missing:

gvMobile.DataSource = mobile.getMobileData().DataSource;

Thank you for the help still.

Upvotes: 1

Related Questions