473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Sorted datagrid on a form and display selected row on a dialog-HELP

kll
I have been on newsgroup for week. I have seen anything that will help me. Basically, I have a form with a datagrid that can be sorted or unsorted (it is up to the user). Then, I display the data of the selected row in textboxes on dialog that execute by the user press a button. The following code works if I do not sort the datagrid before I press the button to bring up the dialog. It is when I sort it the datagrid I have the issue

private void Frm_CustomerAU_Load(object sender, System.EventArgs e

Frm_Customers frmCustomers= (Frm_Customers) this.Owner;

CurrencyManager currencyMgr = (CurrencyManager)this.BindingContext[frmCustomers.tableInfoDG.DataSource, "Table"]

currencyMgr.Position = frmCustomers.tableInfoDG.CurrentRowIndex

DataRow currentRow = ((DataRowView)currencyMgr.Current).Row

txtBxCompanyName.Text= currentRow["CompanyName"].ToString()

I have also tried using the following code to bind the table to the textbox and I get the same result
txtBxCompanyName.DataBindings.Add("Text", frmCustomers.tableInfoDG.DataSource, "Table.CompanyName")

I believe it has something to do what I am setting CurrencyManager position to ( currencyMgr.Position = frmCustomers.tableInfoDG.CurrentRowIndex;). I know I need it to be the position of the underlying table in order to get the selected position in the datagrid. I just do not know how to get the position. By the way, this is C

Any help would be greatly appreciated

Nov 16 '05 #1
1 2367
Try PropertyManager.
private void Current_Changed(object sender, EventArgs e)
{
BindingManagerBase bm = (BindingManagerBase) sender;
/* Check the type of the Current object. If it is not a
DataRowView, exit the method. */
if(bm.Current.GetType() != typeof(DataRowView)) return;

// Otherwise, print the value of the column named "CustName".
DataRowView drv = (DataRowView) bm.Current;
Console.Write("CurrentChanged): ");
Console.Write(drv["CustName"]);
Console.WriteLine();
}

--
================================================== ===
* ÃλÃÈçÕ棡 ¡¡¡¡*
* ÎÒºÜÕæ³Ï£¬µ«ÎÒÉú»îÔÚ»ÑÑÔÖ®ÖС£ ¡¡¡¡*
* ¡¡¡¡*
* ÎÒÅ×ÆúÁËËùÓеÄÓÇÉËÓëÒÉÂÇ£¬È¥×·ÖðÄÇÎ޼ҵij±Ë®£¬ *
* ÖÕÓÚÕÒµ½ÁËÒ»¸ö°®ÎÒµÄÅ®ÈË£¬´Ó´ËʧȥÁË×ÔÓÉ£¡ ¡¡ *
*[csharp] °ßÖñ ÌÀ½¨¾ü ¡¡ ¡¡*
================================================== ===
"kll" <an*******@discussions.microsoft.com> дÈëÏûÏ¢
news:60**********************************@microsof t.com...
I have been on newsgroup for week. I have seen anything that will help me. Basically, I have a form with a datagrid that can be sorted or unsorted
(it is up to the user). Then, I display the data of the selected row in
textboxes on dialog that execute by the user press a button. The following
code works if I do not sort the datagrid before I press the button to bring
up the dialog. It is when I sort it the datagrid I have the issue.
private void Frm_CustomerAU_Load(object sender, System.EventArgs e)
{
Frm_Customers frmCustomers= (Frm_Customers) this.Owner;

CurrencyManager currencyMgr = (CurrencyManager)this.BindingContext[frmCustomers.tableInfoDG.DataSource,
"Table"];
currencyMgr.Position = frmCustomers.tableInfoDG.CurrentRowIndex;

DataRow currentRow = ((DataRowView)currencyMgr.Current).Row;

txtBxCompanyName.Text= currentRow["CompanyName"].ToString();
}
I have also tried using the following code to bind the table to the textbox and I get the same results txtBxCompanyName.DataBindings.Add("Text", frmCustomers.tableInfoDG.DataSource, "Table.CompanyName");
I believe it has something to do what I am setting CurrencyManager position to ( currencyMgr.Position =
frmCustomers.tableInfoDG.CurrentRowIndex;). I know I need it to be the
position of the underlying table in order to get the selected position in
the datagrid. I just do not know how to get the position. By the way, this
is C#
Any help would be greatly appreciated.

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: pcPirate | last post by:
Hi, I have a few questions regarding the C# Datagrid i) I've customised a datagrid with 2 textboxButton (Column1) (Column2) in it. (It's a control with combination of Textbox with a small...
0
by: Empire City | last post by:
I have an ASP.NET form with a DataGrid and Button. I want to put a RadioButtonList in a DataGrid cell. I bind it to an ArrayList which has a ListItem in the cell. The display part works fine. I...
3
by: Doug | last post by:
Hi I have the following code (not mine) that populates a datagrid with some file names. But I want to replace the datagrid with a combo box. private void OnCurrentDataCellChanged(object sender,...
2
by: Alpha | last post by:
I have a window application. In one of the form, a datagrid has a dataview as its datasource. Initial filtering result would give the datavew 3 items. When I double click on the datagrid to edit...
1
by: Empire City | last post by:
I have an ASP.NET form with a DataGrid and Button. I want to put a RadioButtonList in a DataGrid cell. I bind it to an ArrayList which has a ListItem in the cell. The display part works fine. I...
5
by: Jason | last post by:
I've been trying to figure out a good way to do this but haven't had much luck, any input would be greatly appreciated. Basically, after a datagrid is sorted, how can I get the primary key value...
2
by: Bob Hollness | last post by:
Hi group. I am a newbie to ASP.NET as you will see from some of the questions I may ask! I have a datagrid which I have populated from a database. It works great! I have added a column, via...
2
by: Adda | last post by:
I have a datagrid on a parent mdi form with connection1, dataAdapter1, dataset1. From a main menu I call a child form where I enter new data and update dataset1 with dataAdapter2, connection2 on...
3
by: Brian Tkatch | last post by:
I have a form with two DataGrids, which are kept in sync manually via Stored PROCEDURE calls. That is, when a record is selected on the first grid, a stored PROCEDURE is CALLed to Fill() the next...
0
by: SanjayKumarDey | last post by:
I have a vb.net datagrid bound to a dataview on a windows form. I want to use the datagrid to display and filter a list of items , but since the data is complex, I don't want the user to edit the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.