Using System.Windows.Form not greyed - c#

I've created a windows form called Grades and when I click the Submit button, it displays the "System.Windows.Form" onto the label and then the text I've entered onto the textbox. For example, it displays "System.Windows.Form Tom". Now I've been researching online and people say that I should add it as a reference. I already did that and it seems as though that the using statement isn't greyed in like the other using statements. Please Help!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Grades
{
public partial class frmGrades : Form
{
public frmGrades()
{
InitializeComponent();
}
private void btnSubmit_Click(object sender, EventArgs e)
{
lblDisplayStudentName.Text = Convert.ToString(txtBoxStudentName);
lblDisplayMessage.Text = Convert.ToString(txtBoxStudentGrade);
}
}
}

You need to get the text property of the textbox :
lblDisplayStudentName.Text = txtBoxStudentName.Text;
lblDisplayMessage.Text = txtBoxStudentGrade.Text;

Related

Problems plotting in WindowsForm using oxyplot

I'm trying to learnt how to use Oxyplot with WindowsForm, so I just created a WindorsForm and copy the example in Oxyplot guide(https://readthedocs.org/projects/oxyplot/downloads/pdf/latest/) in page 23. So, this is my code
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DocumentFormat.OpenXml.Bibliography;
namespace JuliaForms {
using System;
using System.Windows.Forms;
using OxyPlot;
using OxyPlot.Series;
public partial class Form1 : Form
{
public Form1()
{
this.InitializeComponent();
var myModel = new PlotModel { Title = "Example 1" };
myModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)"));
this.plot1.Model = myModel;
}
}
}
It return me an error, saying that I left a reference or a method. But I have all references and according to the guide I dont need any method. So, could somebody tell me how could I fix the error?
Thanks in advance

how to customize combobox with C#.NET to make the value I chose displays with different value

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partical class Form1 : Form
{
public Form1()
{
InitializeComponent();
comboBox1.Items.Add("key1-value1");
comboBox1.Items.Add("key2-value2");
comboBox1.Items.Add("key3-value3");
}
}
}
for example,the list is like this:
key1-value1
key2-value2
key3-value3
when I choose the third one, the value changes to value3
what I want is like this:https://demos.telerik.com/aspnet-ajax/combobox/examples/overview/defaultcs.aspx
but my project is a WinForm project

Relationship between ComboBox & ListBox

I have a DataSet setup like the following:
As can be seen, there's a relationship between both tables.
In my form page I have the following layout:
The combobox simply select the 'platform' and what I want to get is that the ListBox only shows records that belongs to the relationship, filtered by plataforma_id.
In the TableAdaptor of the Table 'SetupUrlConditions' I have set it up like the following:
When I run the app, the ListBox always shows all records instead of being filtered by the relationship. Changing the ComboBox selected item, the result is always the same.
So, Is there something missing in my code to accomplish this?
Thanks.
EDIT:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Backoffice
{
public partial class SetupRules : Form
{
public SetupRules()
{
InitializeComponent();
}
private void plataformasBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.plataformasBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.plataformasDataSet);
}
private void SetupRules_Load(object sender, EventArgs e)
{
this.plataformasTableAdapter.Fill(this.plataformasDataSet.plataformas);
this.setupUrlConditionsTableAdapter.Fill(this.plataformasDataSet.SetupUrlConditions);
}
}
}
private void PlatformasCBO_SelectedValueChanged(object sender, EventArgs e)
{
if (PlatformasCBO.SelectedValue != null)
{
SiteUrlLstBox.DataSource = this.platformasDataSet.SetupUrlConditions.Where( p => p.platforma_id == (int)PlatformasCBO.SelectedValue).ToList();
}
}
Ok you made me dig for that one since I haven't done it in such a long time...
Combobox = Platformas. Properties to be set are DisplayMember = Plaformas, ValueMember = Id
ListBox just displaymember = condicion?... up to you from there.
Keep in mind that something is always selected with this setup it would need to be modified to have nothing selected initially but out of scope for the question

Dynamic custom asp.net control : ID property?

I would like to create a custom control : a numeric textbox.
I followed this tutorial (http://www.codeproject.com/Articles/42382/Creating-a-Numeric-TextBox-Control) but I'm facing an issue.
I want to create those controls dynamically like that :
NumericTextBox _Quantity = new NumericTextBox();
_Quantity.ID = "_Quantity" + id;
_Quantity.Text = "1";
However, it is said that there is no definition for the "ID" property in NumericTextBox. Yet, this control is TextBox's child, so it should have the ID property, like the Text's one which works well...
using System;
using System.Web.UI;
[assembly: WebResource("CustomControls.Resources.NumericTextBox.js", "text/javascript")]
namespace CustomControls
{
[ToolboxData(#"<{0}:NumericTextBox ID="""" Text="""" runat=""server""></{0}:NumericTextBox>")]
public partial class NumericTextBox : System.Web.UI.WebControls.TextBox
{
// specific code
}
}
Did I miss something ? If I can make this property work, will the FindControl method work with the custom control ?
Thanks a lot !
EDIT :
I have two projects in my solution :
A class library one, "CustomControls", which contains NumericTextBox.cs
And my website.
Here is my page's extract code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using CustomControls;
public partial class MyPage : System.Web.UI.Page
{
protected void AddItem(Enum type, Enum content)
{
string id = (content != null) ? content.ToString() : type.ToString();
...
NumericTextBox _Quantity = new NumericTextBox();
_Quantity.ID = "_Quantity" + id;
_Quantity.Text = "1";
...
}
}
That is strange, in my code it works perfectly:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ButtonTest2
{
[ToolboxData(#"<{0}:NumericTextBox ID="""" Text="""" runat=""server""></{0}:NumericTextBox>")]
public partial class NumericTextBox : TextBox
{
}
}
Instancing:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ButtonTest2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
NumericTextBox tb = new NumericTextBox();
tb.ID = "123";
}
}
}
Do you miss some usings in the class where you create the NumericTextBox instance?
EDIT
FindControl should work with your custom control.

error : 'classA' doesnot exist in current context

I started new project of Windows Forms. First page is UserLogin. in form load event I am taking the logintable from database into memory.
I am using a class in which all read and write operations methods are stored.
when I am calling the class in formload event, the error comes "doesnot exist in current context"
I may be missing some references or headerfilename..
Please Help
Thanks in Advance
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Web;
namespace InvestmentAndReturns
{
public partial class UserLogin : Form
{
public UserLogin()
{
InitializeComponent();
CenterToScreen();
}
public string UserID = null;
private string userPass = null;
public string UserGroup = null;
DataTable UserLoginTable;
int logintry = 1;
public bool LoginStatus = false;
private void Form1_Load(object sender, EventArgs e)
{
txtUserID.Select();
string cmd = "Select * from UserLogin";
UserLoginTable = DbRdRw.SqlDbRead(cmd, "UserLogin");
}
DbRdRw: this is the Class
SqlDbRead: this is read method
i have included that class by directly pasting it in the project folder and then opened solution and then included in the project
It looks like you have copy pasted source file containing definition of DbRdRw from some other project - which mostly means the namespace declaration in the file will be from older project.
Things will work if you change the namespace to your current project InvestmentAndReturns.
However, why are you copy pasting this around? You could make a library dll for your DbRdRw and reference the dll. That way you will keep your source code at one place.

Categories

Resources