Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 513599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:26:20+00:00 2026-05-13T07:26:20+00:00

Hi I have DataGridView control that I manyally fill with items (no DataSource) like

  • 0

Hi I have DataGridView control that I manyally fill with items (no DataSource)

like that

        int row = dgvClients.Rows.Add();
        dgvClients.Rows[row].Cells["ClientObjectID"].Value = somevalue1;
        dgvClients.Rows[row].Cells["ClientCode"].Value = somevalue2;
        dgvClients.Rows[row].Tag = SomeObject1;

Pls note that each row in gridview represents some object and its Tag is set to specific object. Only one row can have Tag reference to one SomeObject. No duplicates.

Now I need to find datagridview ROW having reference to SomeObject. What is the best way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:26:21+00:00Added an answer on May 13, 2026 at 7:26 am

    Here is something I put together that might do what you are describing. It is quick and dirty, but it might get you going:

    I have a blank DataGridView, a combobox, and a textbox on a form. TestObject is a class that is an object with 3 string properties for testing purposes of this example.

    For ease, I initialize a generic list with a few instances of TestObject. I then manually add 3 columns to the datagridview which correspond to the 3 properties of TestObject. I then iterate through the list and manually add them to the datagridview, as well as actually storing the object in the Row’s tag property as well.

    I then fill the combobox with references to the columns in the datagridview. The user will select which column she/he wants to search for, then type the text to match in the textbox.

    I then handle the textbox textchanged event to search the datagridview based on the column that is selected in the combobox and the text in the textbox. For a bigger dataset, you wouldn’t want to handle the textchanged event because it would be too slow to search after every letter change.

    Without using a datatable or datasource, I can’t think of any easy way to search the rows without iterating. I don’t know your requirements, but I would use a bindingsource with a list or set up a datatable at a minimum. With a bindingsource you could also apply a filter and dynamically show only those results that match your search.

    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
    
                List<TestObject> objects = new List<TestObject>
                    {
                            new TestObject("1", "object1", "first"),
                            new TestObject("2", "object2", "nada"),
                            new TestObject("3", "object3", "Hello World!"),
                            new TestObject("4", "object4", "last")
                    };
    
                dataGridView1.Columns.Add("ColID", "ID");
                dataGridView1.Columns.Add("ColName", "Name");
                dataGridView1.Columns.Add("ColInfo", "Info");
    
                foreach (TestObject testObject in objects)
                {
                    int row = dataGridView1.Rows.Add();
                    dataGridView1.Rows[row].Cells["ColID"].Value = testObject.ID;
                    dataGridView1.Rows[row].Cells["ColName"].Value = testObject.Name;
                    dataGridView1.Rows[row].Cells["ColInfo"].Value = testObject.Info;
                    dataGridView1.Rows[row].Tag = testObject;
                }
    
                foreach (DataGridViewColumn col in dataGridView1.Columns)
                {
                    comboBox1.Items.Add(col);
                }
    
                comboBox1.ValueMember = "HeaderText";
                comboBox1.SelectedIndex = 0;
            }
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
                dataGridView1.ClearSelection();
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
    
                    if (row.Cells[((DataGridViewColumn)comboBox1.SelectedItem).Name].Value == null)
                    {
                        continue;
                    }
                    if (row.Cells[((DataGridViewColumn)comboBox1.SelectedItem).Name].Value.ToString().Equals(
                            textBox1.Text,StringComparison.InvariantCultureIgnoreCase))
                    {
                        row.Selected = true;
                        return;
                    }
                }
            }
        }
    }
    
    public class TestObject
    {
        public TestObject(string id, string name, string info)
        {
            ID = id;
            Name = name;
            Info = info;
        }
    
        public string ID { get; set; }
        public string Info { get; set; }
        public string Name { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application I have a DataGridView control that displays data for the selected
I have a DataGridView control in a winforms app that I'm working on. The
I have a custom DataGridView column that uses an embedded control that pops up
I have a WinForms application with a DataGridView control and a column of DataGridViewButtonCell
I have a calendar control derived from DataGridView. A custom item hover event is
I have a DataGridView with its datasource set to a generic list of custom
I have a DataGridView that I want to query using Linq (C# WinForm). I
I have a UserControl with some predefined controls (groupbox,button,datagridview) on it, these controls are
I have a DataGridView with one DataGridViewComboBoxColumn in my WinForms application. I need to
I have a datagridview where the users can select which subset of columns to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.