Solved

C# Hot to query a DataTable and select the Row in DataGrid

Posted on 2006-07-10
4
1,259 Views
Last Modified: 2012-06-27
I have DataTable, Columns in it are ID and Price. I am showing that Datatable using DataGrid.

Now, I have an ID and I want to query my DataTable and if I find that ID in DataTable, I wana select that record in DataGrid.


AnyHelp
0
Comment
Question by:tahir_666
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 250 total points
ID: 17072606
You could use the datatable .select() function to do this.for this u would have to set one of ur columns in the table as a primary key

ATable.Constraints.Add(contraintname,columnname,primarykey)

then u could use Atable.select (string filter exp) to
select corresponding row

exp can be like "COLUMNNAME = VALUE"
or "COLUMNNAME < VALUE"
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 17072622
add to that above if u dont set the primary key the problem would be that there is chance of returning multile rows
0
 

Author Comment

by:tahir_666
ID: 17072652
I can get the Row which I want to select....but I want to select the Row in DB grid, if found.

Anycode for selecting the Row in Datagrid???
0
 

Author Comment

by:tahir_666
ID: 17079375
Found by help of office dude :o)

dgSQL.DataSource = dtSQL2;

                for (int i = 0; i < dtSQL2.Rows.Count; i++)
                {
                    if (dtSQL2.Rows[i]["ORDER_ID"].ToString() == OrderID.ToString())
                    {
                        dgSQL.Rows[i].Selected = true;
                    }
                    else
                    {
                        dgSQL.Rows[i].Selected = false;
                    }
                }
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
"Black Box" Testing of Control System Software 2 125
AvlTree-Node Data type 4 46
print bytes of an integer 6 48
Eclipse neon2 "Java build path" correctness 7 43
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question