Solved

Pass values to to main Form from Popup form Datagrid

Posted on 2004-03-23
22
864 Views
Last Modified: 2008-01-09
hi,

I have a main form with a textbox and i open modal form with  a datadrig, i find a record in datagrid and need return select value to textbox in main form,

please if can wirte a  example  best,

thanks,

and sorry for my little english,

Miguel Machado
0
Comment
Question by:memm
  • 9
  • 5
  • 4
  • +2
22 Comments
 

Author Comment

by:memm
ID: 10659163
sorry,

my question is.

how make form return value in textbox in main form
0
 
LVL 6

Expert Comment

by:gtvingo14
ID: 10659328
here is an example,

<form onSubmit="
if (opener && !opener.closed) {
   opener.document.myForm.field1.value=this.field1.value;
   window.close();
   return false;
} "> 
<input name="field1" value="" type="text">
<input type="submit">
</form>

hope it helps
0
 

Author Comment

by:memm
ID: 10659412
sorry,

i work in .NET Compact FrameWork(Pocket PC 2002)  and VB.NET

thanks,

Miguel Machado
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10659458
Hola Miguel:
gtvingo's solution is for ASP.NET
Are you working with a Windows application or a Web application?
If you are using a windows application then your code should looks something like this:

            Dim f As New Form2
            f.ShowDialog()
            Me.TextBox1 = f.DataGrid1.CurrentCell.ToString

If you are a spanish speaker and want to clarify, you can ask in Spanish, and I will translate for the other experts


Dabas
0
 
LVL 2

Expert Comment

by:HugoCode
ID: 10659490
I think he means a windows form because ASP has not modal dialogs.

To get the selected Row of your datagrid, you can use this code:

Dim objFrmModal as new myDialogForm()
if objFrmModal.ShowDialog() = DialogResult.OK Then
   Dim iSelectedRow as integer
   iSelectedRow = objFrmModal.DataGrid1.CurrentCell.RowNumber()
End If

0
 
LVL 2

Expert Comment

by:HugoCode
ID: 10659506
Dabas post wasn't there when I wrote mine...sorry
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10660491
HugoCode:
No worries. Your code looks good too!

Dabas
0
 

Author Comment

by:memm
ID: 10660690
ok, in spanish

tengo un formulario, desde donde llamo otro formulario modal, el cual contine un datagrid

en este datagrid seleciono un valor (una fila -ROW-) de la cual solo quiero devolver el valor de la primera columna,

a un textbox del formulario principal,

como lo hago

el ejemplo de dadas, devuelve lo siguiente:

Me.txtFamilia.Text = X.DGBusqueda.CurrentCell.ToString   =>
   
  el textbox termina con este valor,    "DataGridCell {RowNumber = 8, ColumnNumber = 0}"

pero especificamente quiero devolver independientemente de la celda selecionada solo la primera columna de esa fila(row)






0
 
LVL 27

Expert Comment

by:Dabas
ID: 10660747
Translation:

I have a form, from which I call a modal form, which has a datagrid
In this datagrid I select a value (a row) from which I want to return just the value in the first column to a textbox in the calling form

How do I do this?

The sample Dabas gave returns the following:

Me.txtFamilia.Text = X.DGBusqueda.CurrentCell.ToString   =>
   
  the textbox finishes up with the following value,    "DataGridCell {RowNumber = 8, ColumnNumber = 0}"

but what I specifically want is to return the value in the first column of this row
0
 
LVL 6

Expert Comment

by:gtvingo14
ID: 10660768
lol, nice...i will call you when I need a translator ;)
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10660826
Miguel:

Try the following:

        Dim col As Integer = f.DataGrid1.CurrentCell.ColumnNumber
        Dim row As Integer = f..DataGrid1.CurrentCell.RowNumber
        Me.TextBox1.Text = f,DataGrid1(row, col)

Dabas
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 27

Assisted Solution

by:Dabas
Dabas earned 85 total points
ID: 10660840
Correction
         Dim col As Integer = f.DataGrid1.CurrentCell.ColumnNumber
         Dim row As Integer = f.DataGrid1.CurrentCell.RowNumber
         Me.TextBox1.Text = f.DataGrid1(row, col)


Dabas
0
 
LVL 10

Accepted Solution

by:
EBatista earned 40 total points
ID: 10661276
hi miguel, use the Owner property when you load Form2:

'loading Form2 modal
Dim f As New Form2
f.Owner=Me
f.ShowDialog()


'Within the Form2, ie in response of a button click:
Me.TextBox1 =CType(Me.Owner, Form1).TexBox1.Text=Me.DataGrid1.CurrentCell.ToString
Me.Close

regards
0
 
LVL 10

Expert Comment

by:EBatista
ID: 10661343
yeah dabas is right about the row and col index, but still have to use the Owner property to retrieve the actual instance of Form1 that has opened f (Form2):

'loading Form2 modal
Dim f As New Form2
f.Owner=Me
f.ShowDialog()


'Within the Form2, ie in response of a button click:
Dim col As Integer = f.DataGrid1.CurrentCell.ColumnNumber
Dim row As Integer = f.DataGrid1.CurrentCell.RowNumber

Me.TextBox1 =CType(Me.Owner, Form1).TexBox1.Text=Me.DataGrid1(row, col)
Me.Close
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10661503
Miguel:

In case you do not know it, I highly recommend the following link:

http://www.elguille.info

Dabas
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10661537
EBatista:
ARe you sure my way does not work? I did not test it, but do know I have written similar code.
After f.ShowDialog, the reference to f is still open in Form1, and its DataGrid accessible from there.

Your code is correct if what Miguel wants is to set TextBox1 from Form2, but then, why open Form2 modally?

Dabas
0
 
LVL 10

Expert Comment

by:EBatista
ID: 10661901
dabas that is why i set the TextBox value from Form2 cos within Form1 he cant, of course i have supposed that after his search give the results, he expects some user action in Form2 like select a row in the datagrid and maybe hit a button too to return the threat to the main form, but in that point the modal will no longer exist.
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10662591
EBatista,
>  but in that point the modal will no longer exist.
The modal form is not visible, but it still exists, while the variable f is within scope

Dabas
0
 
LVL 10

Expert Comment

by:EBatista
ID: 10663345
hi dabas, with Me.Close() the form will be closed, the variable f will be within scope but f will keeps its members values? ie DataGrid1 cells values, textboxes properties..etc.
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10663410
EBatista,
Lets assume that there is an OK button on Form2.
If this OK button has its DialogResult property set to OK then when the user clicks on this button, Form2 hides (but its members are still available) and there is no need for your Me.Close()
My code will then be valid


Dabas
0
 

Author Comment

by:memm
ID: 10665318
jejeje...  very very well

un poco larga su discución

i test the solution of DABAS, and work fine,

but later test EBatista Solution,

Thanks for Dabas,
Thanks for Ebatista,

0
 
LVL 10

Expert Comment

by:EBatista
ID: 10665780
you are right too Dabas, now miguel have two ways to address this issue,
cheers
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vb.net/SQL prevent a table from being deleted ever 7 34
Spacing between controls 4 30
Help with solving error related to resources file 4 35
how to read json value 2 29
A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

919 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

12 Experts available now in Live!

Get 1:1 Help Now