all groups > dotnet windows forms > april 2004 >
You're in the

dotnet windows forms

group:

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



Sorted datagrid on a form and display selected row on a dialog-HELP kll
4/30/2004 6:26:02 PM
dotnet windows forms: 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
Re: Sorted datagrid on a form and display selected row on a dialog-HELP ÌÀ½¨¾ü
5/1/2004 2:11:24 PM
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" <anonymous@discussions.microsoft.com> дÈëÏûÏ¢
news:60706CAB-A110-4572-9FD0-205E64D3D48C@microsoft.com...
[quoted text, click to view]
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.
[quoted text, click to view]
(CurrencyManager)this.BindingContext[frmCustomers.tableInfoDG.DataSource,
"Table"];
[quoted text, click to view]
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#
[quoted text, click to view]

AddThis Social Bookmark Button