TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
mahesh waghela
NA
93
114.1k
Ambiguous Method Of Show And ShowDialog For Displaying Winform
Oct 29 2011 12:34 AM
I am struggling between
Show
and
ShowDialog
method of Showing/Display of Window Form. I am generally use show method instead of ShowDialog method. And ShowDialog Method is utilize when I don't want to show the forms at
ALT+TAB ToolWindow.
The ShowDialog method is shows
model window form
which is having limited access than normal window form. The model window form is not accessing value of control and object which already passed on normal window form hence We have to provide the new value on each time or every time of new instance of forms which's real example is as under.
//Purchase_Entry having a public method which is calling from form30 as under:
public
partial
class
purchase_Entry :
Form
{
public
purchase_Entry()
{
InitializeComponent
();
}
public
void
Purchase_Binding
()
{
mydgv.
Location
=
new
Point
(
0
,
110
);
mydgv.
RowHeadersVisible
=
false
;
mydgv.
Width
= panel2.
Width
;
mydgv.
Height
= panel2.
Height
-
220
;
mydgv.
TabIndex
=
4
;
string
connstr =
"server=.;initial catalog=maa;uid=mah;pwd=mah"
;
SqlConnection
con =
new
SqlConnection
(connstr);
con.
Open
();
string
sql =
@"select billno,date=convert(varchar,date,103),ledgeraccount,totcts,rround,grosspurchase,taxes,taxamt,totdb,narrat"
+
" from depurchasea where companyID=@companyID"
+
" and transID=@transID"
+
" group by billno,date,ledgeraccount,totcts,rround,grosspurchase,taxes,taxamt,totdb,narrat"
+
" order by date,billno"
;
SqlCommand
cmd =
new
SqlCommand
(sql, con);
cmd.
Parameters
.
AddWithValue
(
"companyID"
, label6.
Text
);
cmd.
Parameters
.
AddWithValue
(
"transID"
, textBox5.
Text
);
SqlDataAdapter
dap =
new
SqlDataAdapter
(cmd);
DataSet
ds =
new
DataSet
();
dap.
Fill
(ds);
for
(
int
i =
0
; i < ds.
Tables
[
0
].
Rows
.
Count
; i++)
{
textBox2.
Text
=
Convert
.
ToString
(ds.
Tables
[
0
].
Rows
[i][
"billno"
]);
maskedTextBox1.
Text
=
Convert
.
ToString
(ds.
Tables
[
0
].
Rows
[i][
"date"
]);
textBox1.
Text
=
Convert
.
ToString
(ds.
Tables
[
0
].
Rows
[i][
"ledgeraccount"
]);
textBox9.
Text
=
Convert
.
ToString
(ds.
Tables
[
0
].
Rows
[i][
"totcts"
]);
textBox7.
Text
=
Convert
.
ToString
(ds.
Tables
[
0
].
Rows
[i][
"rround"
]);
textBox13.
Text
=
Convert
.
ToString
(ds.
Tables
[
0
].
Rows
[i][
"grosspurchase"
]);
comboBox1.
Text
=
Convert
.
ToString
(ds.
Tables
[
0
].
Rows
[i][
"taxes"
]);
textBox8.
Text
=
Convert
.
ToString
(ds.
Tables
[
0
].
Rows
[i][
"taxamt"
]);
textBox6.
Text
=
Convert
.
ToString
(ds.
Tables
[
0
].
Rows
[i][
"totdb"
]);
textBox3.
Text
=
Convert
.
ToString
(ds.
Tables
[
0
].
Rows
[i][
"narrat"
]);
}
//mydgv.Columns.Clear();
string
mysql =
"select srno,particulars,carats,rate,debit from depurchasea"
+
" where companyID=@companyID"
+
" and transID=@transID"
;
SqlCommand
mycmd =
new
SqlCommand
(mysql, con);
mycmd.
Parameters
.
AddWithValue
(
"companyID"
, label6.
Text
);
mycmd.
Parameters
.
AddWithValue
(
"transID"
, textBox5.
Text
);
SqlDataAdapter
mydap =
new
SqlDataAdapter
(mycmd);
DataSet
myds =
new
DataSet
();
mydap.
Fill
(myds);
mybinding =
new
BindingSource
();
mybinding.
DataSource
= myds;
mybinding.
DataMember
= myds.
Tables
[
0
].
TableName
;
mydgv.
DataSource
= mybinding;
mydgv
.
Columns
[
0
].
HeaderText
=
"Sr.No."
;
mydgv
.
Columns
[
1
].
HeaderText
=
"Particulars"
;
mydgv
.
Columns
[
2
].
HeaderText
=
"Carats"
;
mydgv
.
Columns
[
3
].
HeaderText
=
"Rate"
;
mydgv
.
Columns
[
4
].
HeaderText
=
"Amount"
;
mydgv
.
Columns
[
0
].
Width
=
50
;
mydgv
.
Columns
[
1
].
Width
=
500
;
mydgv
.
Columns
[
4
].
Width
=
100
;
mydgv
.
Columns
[
2
].
Width
=
100
;
mydgv
.
Columns
[
3
].
Width
=
100
;
mydgv
.
Columns
[
2
].
DefaultCellStyle
.
Alignment
=
DataGridViewContentAlignment
.
BottomRight
;
mydgv
.
Columns
[
3
].
DefaultCellStyle
.
Alignment
=
DataGridViewContentAlignment
.
BottomRight
;
mydgv
.
Columns
[
4
].
DefaultCellStyle
.
Alignment
=
DataGridViewContentAlignment
.
BottomRight
;
mydgv
.
Columns
[
2
].
DefaultCellStyle
.
Format
=
"f2"
;
mydgv
.
Columns
[
3
].
DefaultCellStyle
.
Format
=
"f2"
;
mydgv
.
Columns
[
4
].
DefaultCellStyle
.
Format
=
"f2"
;
mydgv
.
Columns
[
4
].
ReadOnly
=
true
;
int
dgvsize
=
mydgv
.
Width
/
17
;
mydgv
.
Columns
[
0
].
Width
=
dgvsize
;
mydgv
.
Columns
[
1
].
Width
=
dgvsize
*
10
;
mydgv
.
Columns
[
2
].
Width
=
dgvsize
*
2
;
mydgv
.
Columns
[
3
].
Width
=
dgvsize
*
2
;
mydgv
.
Columns
[
4
].
Width
=
dgvsize
*
2
;
mydgv
.
Refresh
();
if
(
textBox13
.
Text
!=
""
)
{
decimal
res
=
Convert
.
ToDecimal
(
textBox13
.
Text
);
textBox13
.
Text
=
res
.
ToString
(
"f2"
);
}
}
public
partial
class
Form30
:
Form
{
public
Form30
()
{
InitializeComponent
();
}
private
void
listView1_KeyPress
(
object
sender
,
KeyPressEventArgs
e
)
{
else
if
(
textBox2
.
Text
==
"Purchase"
)
{
purchase_Entry pc
=
new
purchase_Entry
();
pc
.
lbl6
.
Text
=
pp
.
Form1
.
IDD
.
Text
;
//companyID
pc
.
Purchase_Binding
()
//Calling public method of purchase_entry Class
pc
.
ShowDialog
(
this
);
pc
.
textboxKeypress
+=
new
purchase_Entry
.
Action
(
pc_textboxKeypress
);
pc
.
purkeydown
+=
new
purchase_Entry
.
Action
(
pc_purkeydown
);
}
}
The Calling
Purchase_Binding()
method from
purchase_Entry
Form on
Show()
method is working very well but if I use the same at
ShowDialog()
method than it will display the records but the alignment of controls are changed. that's means I have to issue new value of each control size,height,width and companyID on instance showing at
ShowDialog()
Method.
If So than it will donkey works for me.because I have to redesign purchase_Entry on ShowDialog() method.
What is the best way?.
If I deal with
Show()
method than form will show at
ALT+TAB ToolWindow
and I don't want to allow to show it at
ALT+TAB ToolWindow
that's why I am used
ShowDialog() Method
which will showing as model window form and will not displaying at ALT+TAB ToolWindow.
And If I use the ShowDialog() method than I have to be ready to redesign it like donkey works. Isn't It?.
Reply
Answers (
2
)
RowValidating in master/detail scenario
How to capture signature