0

I have sucessfully populated a datagrid view from a list. The problem lies with trying to change the data source after a search has been initiated.

I'm sucessfully returning intended results from the below code.

        int ResultIndex = 0;
        for (int i = 0; i < Members.Count; i++)
        {
            if (Members[i].ToonName == ToonSearchName.Text)
            {
                ResultIndex = i;
                break;
            }
        }
        var Source = new BindingSource();


        MessageBox.Show(ResultIndex.ToString()); // Returns the correct Index
        MessageBox.Show(Members[ResultIndex].ID); // Returns the correct value

        MemberListView.AutoGenerateColumns = true;
        MemberListView.Columns.Clear();
        MemberListView.DataSource = this.Members[ResultIndex]; // Datagrid view turns blank after this line

The actual list is as followed:

     public class DVMemberlist
        {

            public string ID { get; set; }
            public string ToonName { get; set; }
            public string AddedOn { get; set; }
            public string AddedBy { get; set; }
            public string Enteries { get; set; }


        }

It seems even know i'm able to print expected data into the message box, when trying to change the data source for the datagridview it empties and is blank rather showing 1 row.

First picture is the populated data when the form is loaded. Which is exactly as intended.

Correctly populated data

The second image is after the search has been performed for "Ocz7ok3MqH" which message boxes show the intended ID and the intended index. But the datagridview is returned blank

Unintended Results

Daryl Gill
  • 5,464
  • 9
  • 36
  • 69
  • 1
    You clear the columns and use an entirely different datasource, one which doesnt even appear to be a collection. There is a wonderful property called `RowFilter` for a proper `DataGridView` filter and even a `DataView` for more extensive operations – Ňɏssa Pøngjǣrdenlarp Jan 23 '20 at 17:49
  • Nyssa was spot on. My [explanation](https://stackoverflow.com/a/31818204/3773066) on `RowFilter` behavior might help. – OhBeWise Jan 24 '20 at 20:13

0 Answers0