Solved

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

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now