Solved

Pass values to to main Form from Popup form Datagrid

Posted on 2004-03-23
22
867 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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
 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

735 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