[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 877
  • Last Modified:

Pass values to to main Form from Popup form Datagrid

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
memm
Asked:
memm
  • 9
  • 5
  • 4
  • +2
2 Solutions
 
memmAuthor Commented:
sorry,

my question is.

how make form return value in textbox in main form
0
 
gtvingo14Commented:
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
 
memmAuthor Commented:
sorry,

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

thanks,

Miguel Machado
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
DabasCommented:
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
 
HugoCodeCommented:
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
 
HugoCodeCommented:
Dabas post wasn't there when I wrote mine...sorry
0
 
DabasCommented:
HugoCode:
No worries. Your code looks good too!

Dabas
0
 
memmAuthor Commented:
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
 
DabasCommented:
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
 
gtvingo14Commented:
lol, nice...i will call you when I need a translator ;)
0
 
DabasCommented:
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
 
DabasCommented:
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
 
EBatistaCommented:
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
 
EBatistaCommented:
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
 
DabasCommented:
Miguel:

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

http://www.elguille.info

Dabas
0
 
DabasCommented:
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
 
EBatistaCommented:
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
 
DabasCommented:
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
 
EBatistaCommented:
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
 
DabasCommented:
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
 
memmAuthor Commented:
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
 
EBatistaCommented:
you are right too Dabas, now miguel have two ways to address this issue,
cheers
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 9
  • 5
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now