Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 104
groupSum6 challenge 6 99
Run AutoHotkey script directly from Notepad++ 5 56
Selenium docs api java index 3 48
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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…

809 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