private void button1_Click(object sender, EventArgs e) { //Get the combo choice, if there is any. string strGenre = cbxGenre.SelectedIndex > -1 ? cbxGenre.SelectedItem.ToString() : string.Empty; //Declare the books array; though the actual return type is List<Books>, it actually gets casted into //Book[] array. Book[] lstBooks = null; //Discard other filters, if user has entered a book id if (!string.IsNullOrEmpty(txtID.Text)) { lstBooks = bookService.GetBookByID(txtID.Text); } else { //Lets get books by filter. lstBooks = bookService.Filter(Author: txtAuthor.Text, Title: TxtTitle.Text, Genre: strGenre); } //Set datasource, custom object. dataGridView1.DataSource = lstBooks; }