Solved

Pass values to to main Form from Popup form Datagrid

Posted on 2004-03-23
22
863 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
Comment Utility
sorry,

my question is.

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

Expert Comment

by:gtvingo14
Comment Utility
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
Comment Utility
sorry,

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

thanks,

Miguel Machado
0
 
LVL 27

Expert Comment

by:Dabas
Comment Utility
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
Comment Utility
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
Comment Utility
Dabas post wasn't there when I wrote mine...sorry
0
 
LVL 27

Expert Comment

by:Dabas
Comment Utility
HugoCode:
No worries. Your code looks good too!

Dabas
0
 

Author Comment

by:memm
Comment Utility
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
Comment Utility
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
Comment Utility
lol, nice...i will call you when I need a translator ;)
0
 
LVL 27

Expert Comment

by:Dabas
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 27

Assisted Solution

by:Dabas
Dabas earned 85 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
you are right too Dabas, now miguel have two ways to address this issue,
cheers
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

10 Experts available now in Live!

Get 1:1 Help Now