How to pass a value from one form to a private TextBox in another Form via a pubic static class?
I have an Invoice form with several private TextBoxes. I want to pass some values from my DataGridView in search form to those TextBoxes in Invoice form(when I press Enter for example).
What I want to do is to pass the values of the current selected row in the DataGridView to be passed to certain TextBoxes in Invoice Form:
I could illustrate this in the following code:
(I know how to get the values of selected row in datagridview my question is just the title...)
if (e.KeyCode == Keys.Enter)
{
SqlCommand sqlcmd = new SqlCommand("SELECT ID FROM X WHERE ID=" +
dataGridView1.CurrentRow.Cells[0].Value + "", sqlcon);
SqlDataReader sqldr = sqlcmd.ExecuteReader();
while (sqldr.Read())
{
InvoiceForm.CodeTextBox = sqldr[codecolumn].Tostring
InvoiceForm.NameTextBox = sqldr[Namecolumn].Tostring
InvoiceForm.BlahTextBox = sqldr[Blahcolumn].Tostring
}
}
which throws the following error at me:
codeTextBox is private... not able to do so because of protection
level...
I think I have to make a public static class to do so, but I dont know how.
How I tried:
private string RetrivedCode;
private string RetrivedName;
private int RetrivedQTY;
...
Public Form1(string CodeTextBox , string NameTextBox, string BlahTextBox)
{
this.CodeTextBox= RetrivedCode;
this.NameTextBox= RetrivedName;
... and so On
}
which errors:
cannot implicitly convert type 'string' to
'system.windows.forms.textbox'.
c# class constructor static public
add a comment |
I have an Invoice form with several private TextBoxes. I want to pass some values from my DataGridView in search form to those TextBoxes in Invoice form(when I press Enter for example).
What I want to do is to pass the values of the current selected row in the DataGridView to be passed to certain TextBoxes in Invoice Form:
I could illustrate this in the following code:
(I know how to get the values of selected row in datagridview my question is just the title...)
if (e.KeyCode == Keys.Enter)
{
SqlCommand sqlcmd = new SqlCommand("SELECT ID FROM X WHERE ID=" +
dataGridView1.CurrentRow.Cells[0].Value + "", sqlcon);
SqlDataReader sqldr = sqlcmd.ExecuteReader();
while (sqldr.Read())
{
InvoiceForm.CodeTextBox = sqldr[codecolumn].Tostring
InvoiceForm.NameTextBox = sqldr[Namecolumn].Tostring
InvoiceForm.BlahTextBox = sqldr[Blahcolumn].Tostring
}
}
which throws the following error at me:
codeTextBox is private... not able to do so because of protection
level...
I think I have to make a public static class to do so, but I dont know how.
How I tried:
private string RetrivedCode;
private string RetrivedName;
private int RetrivedQTY;
...
Public Form1(string CodeTextBox , string NameTextBox, string BlahTextBox)
{
this.CodeTextBox= RetrivedCode;
this.NameTextBox= RetrivedName;
... and so On
}
which errors:
cannot implicitly convert type 'string' to
'system.windows.forms.textbox'.
c# class constructor static public
add a comment |
I have an Invoice form with several private TextBoxes. I want to pass some values from my DataGridView in search form to those TextBoxes in Invoice form(when I press Enter for example).
What I want to do is to pass the values of the current selected row in the DataGridView to be passed to certain TextBoxes in Invoice Form:
I could illustrate this in the following code:
(I know how to get the values of selected row in datagridview my question is just the title...)
if (e.KeyCode == Keys.Enter)
{
SqlCommand sqlcmd = new SqlCommand("SELECT ID FROM X WHERE ID=" +
dataGridView1.CurrentRow.Cells[0].Value + "", sqlcon);
SqlDataReader sqldr = sqlcmd.ExecuteReader();
while (sqldr.Read())
{
InvoiceForm.CodeTextBox = sqldr[codecolumn].Tostring
InvoiceForm.NameTextBox = sqldr[Namecolumn].Tostring
InvoiceForm.BlahTextBox = sqldr[Blahcolumn].Tostring
}
}
which throws the following error at me:
codeTextBox is private... not able to do so because of protection
level...
I think I have to make a public static class to do so, but I dont know how.
How I tried:
private string RetrivedCode;
private string RetrivedName;
private int RetrivedQTY;
...
Public Form1(string CodeTextBox , string NameTextBox, string BlahTextBox)
{
this.CodeTextBox= RetrivedCode;
this.NameTextBox= RetrivedName;
... and so On
}
which errors:
cannot implicitly convert type 'string' to
'system.windows.forms.textbox'.
c# class constructor static public
I have an Invoice form with several private TextBoxes. I want to pass some values from my DataGridView in search form to those TextBoxes in Invoice form(when I press Enter for example).
What I want to do is to pass the values of the current selected row in the DataGridView to be passed to certain TextBoxes in Invoice Form:
I could illustrate this in the following code:
(I know how to get the values of selected row in datagridview my question is just the title...)
if (e.KeyCode == Keys.Enter)
{
SqlCommand sqlcmd = new SqlCommand("SELECT ID FROM X WHERE ID=" +
dataGridView1.CurrentRow.Cells[0].Value + "", sqlcon);
SqlDataReader sqldr = sqlcmd.ExecuteReader();
while (sqldr.Read())
{
InvoiceForm.CodeTextBox = sqldr[codecolumn].Tostring
InvoiceForm.NameTextBox = sqldr[Namecolumn].Tostring
InvoiceForm.BlahTextBox = sqldr[Blahcolumn].Tostring
}
}
which throws the following error at me:
codeTextBox is private... not able to do so because of protection
level...
I think I have to make a public static class to do so, but I dont know how.
How I tried:
private string RetrivedCode;
private string RetrivedName;
private int RetrivedQTY;
...
Public Form1(string CodeTextBox , string NameTextBox, string BlahTextBox)
{
this.CodeTextBox= RetrivedCode;
this.NameTextBox= RetrivedName;
... and so On
}
which errors:
cannot implicitly convert type 'string' to
'system.windows.forms.textbox'.
c# class constructor static public
c# class constructor static public
asked Nov 21 '18 at 15:13
Daniel_RanjbarDaniel_Ranjbar
828
828
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Have you tried to change the access level of your CodeTextBox to public inside the InvoiceForm which is called InvoiceForm.Designer.cs file.
what a good point. what word should I look for in InvoiceForm.Designer.cs?
– Daniel_Ranjbar
Nov 22 '18 at 10:51
CodeTextBox i think that is the attribute name of your TextBox
– klitz
Nov 23 '18 at 1:30
add a comment |
Well, the error is quite clear, you're trying to convert type 'string' to 'system.windows.forms.textbox'.
while (sqldr.Read())
{
//textbox string
InvoiceForm.CodeTextBox = sqldr[codecolumn].Tostring();
InvoiceForm.NameTextBox = sqldr[Namecolumn].Tostring();
InvoiceForm.BlahTextBox = sqldr[Blahcolumn].Tostring();
}
if you instead set the text property on the textbox, the error goes away.
while (sqldr.Read())
{
// Note the ´Text´ property.
InvoiceForm.CodeTextBox.Text = sqldr[codecolumn].Tostring();
InvoiceForm.NameTextBox.Text = sqldr[Namecolumn].Tostring();
InvoiceForm.BlahTextBox.Text = sqldr[Blahcolumn].Tostring();
}
UPDATE:
The same thing really, even if it's the second part that is the part that is throwing errors. I assume CodeTextBox is a text box?
this.CodeTextBox.Text = RetrivedCode;
this.NameTextBox.Text = RetrivedName;
But you're asking the wrong question. Because you don't have to "make a public static class to do so". If you make your textboxes protected (if your second form inherits the first form) or public instead of private, you'll be able to assign the value directly in accordance with my first examples.
If your text box neccessarily has to be private, use a public or protected accessor or a public method that sets the value of the Text property of the Text boxes.
you completely got my question wrong... . the error you talked about is for my second code block not for my frist code block.
– Daniel_Ranjbar
Nov 21 '18 at 16:11
See edit: The error is still clear and the solution the same. But the question you're asking is probably not the one you need answered.
– Jerri Kangasniemi
Nov 21 '18 at 21:02
@absolute455 are you having any progress? Did you try to set you textboxes to public according to my edit and then set the text property?
– Jerri Kangasniemi
Nov 22 '18 at 12:36
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415069%2fhow-to-pass-a-value-from-one-form-to-a-private-textbox-in-another-form-via-a-pub%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Have you tried to change the access level of your CodeTextBox to public inside the InvoiceForm which is called InvoiceForm.Designer.cs file.
what a good point. what word should I look for in InvoiceForm.Designer.cs?
– Daniel_Ranjbar
Nov 22 '18 at 10:51
CodeTextBox i think that is the attribute name of your TextBox
– klitz
Nov 23 '18 at 1:30
add a comment |
Have you tried to change the access level of your CodeTextBox to public inside the InvoiceForm which is called InvoiceForm.Designer.cs file.
what a good point. what word should I look for in InvoiceForm.Designer.cs?
– Daniel_Ranjbar
Nov 22 '18 at 10:51
CodeTextBox i think that is the attribute name of your TextBox
– klitz
Nov 23 '18 at 1:30
add a comment |
Have you tried to change the access level of your CodeTextBox to public inside the InvoiceForm which is called InvoiceForm.Designer.cs file.
Have you tried to change the access level of your CodeTextBox to public inside the InvoiceForm which is called InvoiceForm.Designer.cs file.
answered Nov 22 '18 at 9:03
klitzklitz
285
285
what a good point. what word should I look for in InvoiceForm.Designer.cs?
– Daniel_Ranjbar
Nov 22 '18 at 10:51
CodeTextBox i think that is the attribute name of your TextBox
– klitz
Nov 23 '18 at 1:30
add a comment |
what a good point. what word should I look for in InvoiceForm.Designer.cs?
– Daniel_Ranjbar
Nov 22 '18 at 10:51
CodeTextBox i think that is the attribute name of your TextBox
– klitz
Nov 23 '18 at 1:30
what a good point. what word should I look for in InvoiceForm.Designer.cs?
– Daniel_Ranjbar
Nov 22 '18 at 10:51
what a good point. what word should I look for in InvoiceForm.Designer.cs?
– Daniel_Ranjbar
Nov 22 '18 at 10:51
CodeTextBox i think that is the attribute name of your TextBox
– klitz
Nov 23 '18 at 1:30
CodeTextBox i think that is the attribute name of your TextBox
– klitz
Nov 23 '18 at 1:30
add a comment |
Well, the error is quite clear, you're trying to convert type 'string' to 'system.windows.forms.textbox'.
while (sqldr.Read())
{
//textbox string
InvoiceForm.CodeTextBox = sqldr[codecolumn].Tostring();
InvoiceForm.NameTextBox = sqldr[Namecolumn].Tostring();
InvoiceForm.BlahTextBox = sqldr[Blahcolumn].Tostring();
}
if you instead set the text property on the textbox, the error goes away.
while (sqldr.Read())
{
// Note the ´Text´ property.
InvoiceForm.CodeTextBox.Text = sqldr[codecolumn].Tostring();
InvoiceForm.NameTextBox.Text = sqldr[Namecolumn].Tostring();
InvoiceForm.BlahTextBox.Text = sqldr[Blahcolumn].Tostring();
}
UPDATE:
The same thing really, even if it's the second part that is the part that is throwing errors. I assume CodeTextBox is a text box?
this.CodeTextBox.Text = RetrivedCode;
this.NameTextBox.Text = RetrivedName;
But you're asking the wrong question. Because you don't have to "make a public static class to do so". If you make your textboxes protected (if your second form inherits the first form) or public instead of private, you'll be able to assign the value directly in accordance with my first examples.
If your text box neccessarily has to be private, use a public or protected accessor or a public method that sets the value of the Text property of the Text boxes.
you completely got my question wrong... . the error you talked about is for my second code block not for my frist code block.
– Daniel_Ranjbar
Nov 21 '18 at 16:11
See edit: The error is still clear and the solution the same. But the question you're asking is probably not the one you need answered.
– Jerri Kangasniemi
Nov 21 '18 at 21:02
@absolute455 are you having any progress? Did you try to set you textboxes to public according to my edit and then set the text property?
– Jerri Kangasniemi
Nov 22 '18 at 12:36
add a comment |
Well, the error is quite clear, you're trying to convert type 'string' to 'system.windows.forms.textbox'.
while (sqldr.Read())
{
//textbox string
InvoiceForm.CodeTextBox = sqldr[codecolumn].Tostring();
InvoiceForm.NameTextBox = sqldr[Namecolumn].Tostring();
InvoiceForm.BlahTextBox = sqldr[Blahcolumn].Tostring();
}
if you instead set the text property on the textbox, the error goes away.
while (sqldr.Read())
{
// Note the ´Text´ property.
InvoiceForm.CodeTextBox.Text = sqldr[codecolumn].Tostring();
InvoiceForm.NameTextBox.Text = sqldr[Namecolumn].Tostring();
InvoiceForm.BlahTextBox.Text = sqldr[Blahcolumn].Tostring();
}
UPDATE:
The same thing really, even if it's the second part that is the part that is throwing errors. I assume CodeTextBox is a text box?
this.CodeTextBox.Text = RetrivedCode;
this.NameTextBox.Text = RetrivedName;
But you're asking the wrong question. Because you don't have to "make a public static class to do so". If you make your textboxes protected (if your second form inherits the first form) or public instead of private, you'll be able to assign the value directly in accordance with my first examples.
If your text box neccessarily has to be private, use a public or protected accessor or a public method that sets the value of the Text property of the Text boxes.
you completely got my question wrong... . the error you talked about is for my second code block not for my frist code block.
– Daniel_Ranjbar
Nov 21 '18 at 16:11
See edit: The error is still clear and the solution the same. But the question you're asking is probably not the one you need answered.
– Jerri Kangasniemi
Nov 21 '18 at 21:02
@absolute455 are you having any progress? Did you try to set you textboxes to public according to my edit and then set the text property?
– Jerri Kangasniemi
Nov 22 '18 at 12:36
add a comment |
Well, the error is quite clear, you're trying to convert type 'string' to 'system.windows.forms.textbox'.
while (sqldr.Read())
{
//textbox string
InvoiceForm.CodeTextBox = sqldr[codecolumn].Tostring();
InvoiceForm.NameTextBox = sqldr[Namecolumn].Tostring();
InvoiceForm.BlahTextBox = sqldr[Blahcolumn].Tostring();
}
if you instead set the text property on the textbox, the error goes away.
while (sqldr.Read())
{
// Note the ´Text´ property.
InvoiceForm.CodeTextBox.Text = sqldr[codecolumn].Tostring();
InvoiceForm.NameTextBox.Text = sqldr[Namecolumn].Tostring();
InvoiceForm.BlahTextBox.Text = sqldr[Blahcolumn].Tostring();
}
UPDATE:
The same thing really, even if it's the second part that is the part that is throwing errors. I assume CodeTextBox is a text box?
this.CodeTextBox.Text = RetrivedCode;
this.NameTextBox.Text = RetrivedName;
But you're asking the wrong question. Because you don't have to "make a public static class to do so". If you make your textboxes protected (if your second form inherits the first form) or public instead of private, you'll be able to assign the value directly in accordance with my first examples.
If your text box neccessarily has to be private, use a public or protected accessor or a public method that sets the value of the Text property of the Text boxes.
Well, the error is quite clear, you're trying to convert type 'string' to 'system.windows.forms.textbox'.
while (sqldr.Read())
{
//textbox string
InvoiceForm.CodeTextBox = sqldr[codecolumn].Tostring();
InvoiceForm.NameTextBox = sqldr[Namecolumn].Tostring();
InvoiceForm.BlahTextBox = sqldr[Blahcolumn].Tostring();
}
if you instead set the text property on the textbox, the error goes away.
while (sqldr.Read())
{
// Note the ´Text´ property.
InvoiceForm.CodeTextBox.Text = sqldr[codecolumn].Tostring();
InvoiceForm.NameTextBox.Text = sqldr[Namecolumn].Tostring();
InvoiceForm.BlahTextBox.Text = sqldr[Blahcolumn].Tostring();
}
UPDATE:
The same thing really, even if it's the second part that is the part that is throwing errors. I assume CodeTextBox is a text box?
this.CodeTextBox.Text = RetrivedCode;
this.NameTextBox.Text = RetrivedName;
But you're asking the wrong question. Because you don't have to "make a public static class to do so". If you make your textboxes protected (if your second form inherits the first form) or public instead of private, you'll be able to assign the value directly in accordance with my first examples.
If your text box neccessarily has to be private, use a public or protected accessor or a public method that sets the value of the Text property of the Text boxes.
edited Nov 21 '18 at 21:01
answered Nov 21 '18 at 16:08
Jerri KangasniemiJerri Kangasniemi
369219
369219
you completely got my question wrong... . the error you talked about is for my second code block not for my frist code block.
– Daniel_Ranjbar
Nov 21 '18 at 16:11
See edit: The error is still clear and the solution the same. But the question you're asking is probably not the one you need answered.
– Jerri Kangasniemi
Nov 21 '18 at 21:02
@absolute455 are you having any progress? Did you try to set you textboxes to public according to my edit and then set the text property?
– Jerri Kangasniemi
Nov 22 '18 at 12:36
add a comment |
you completely got my question wrong... . the error you talked about is for my second code block not for my frist code block.
– Daniel_Ranjbar
Nov 21 '18 at 16:11
See edit: The error is still clear and the solution the same. But the question you're asking is probably not the one you need answered.
– Jerri Kangasniemi
Nov 21 '18 at 21:02
@absolute455 are you having any progress? Did you try to set you textboxes to public according to my edit and then set the text property?
– Jerri Kangasniemi
Nov 22 '18 at 12:36
you completely got my question wrong... . the error you talked about is for my second code block not for my frist code block.
– Daniel_Ranjbar
Nov 21 '18 at 16:11
you completely got my question wrong... . the error you talked about is for my second code block not for my frist code block.
– Daniel_Ranjbar
Nov 21 '18 at 16:11
See edit: The error is still clear and the solution the same. But the question you're asking is probably not the one you need answered.
– Jerri Kangasniemi
Nov 21 '18 at 21:02
See edit: The error is still clear and the solution the same. But the question you're asking is probably not the one you need answered.
– Jerri Kangasniemi
Nov 21 '18 at 21:02
@absolute455 are you having any progress? Did you try to set you textboxes to public according to my edit and then set the text property?
– Jerri Kangasniemi
Nov 22 '18 at 12:36
@absolute455 are you having any progress? Did you try to set you textboxes to public according to my edit and then set the text property?
– Jerri Kangasniemi
Nov 22 '18 at 12:36
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415069%2fhow-to-pass-a-value-from-one-form-to-a-private-textbox-in-another-form-via-a-pub%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown