Solved

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

Posted on 2006-07-10
4
1,256 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

735 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