如何获取datagridview选定的行值到另一个Windows窗体C#中的文本框 [英] how to get datagridview selected row value to text box which is in another windows form c#

查看:232
本文介绍了如何获取datagridview选定的行值到另一个Windows窗体C#中的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取datagridview选定的行值到文本框,单选按钮和下拉列表,该表单在另一个Windows窗体中以C#格式显示为最新日期

得到此错误(对象引用未设置为对象的实例.)


这是我的form1代码
--------------------------
公共静态字符串性别,分区,类型,事件,记分,中继,注释,选择方式;
public static int回合,Scoreteam,时间精度,晋级




公共frmAddEditEvents()
{
如果(Selectmode =="update")
fillRecord();
如果(Selectmode ==插入")
InitializeComponent();


}


公共无效fillRecord()
{



rdbMale.Text =性别;
cmbDivison.Text =除法;
rdbRun.Text =类型;
cmbEvent.Text =事件;
chkScore.Text = Scoreeve;
chkRelay.Text =中继;
nudRounds.Value =回合;
nudScores.Value = Scoreteam;
nudTimeprecision.Value = timeprecison;
txtEventnote.Text =注释;
numericUpDown1.Value =进度;
btnSave.Text ="update";
}

这是表格2
-------------------------


私有void tsbtnEdit_Click(对象发送者,EventArgs e)
{


如果(grdEvents.SelectedRows.Count> 0)
{



frmAddEditEvents.Selectmode ="update" ;;

frmAddEditEvents.Gender = Convert.ToString(grdEvents.SelectedRows [0] .Cells [1] .Value);

frmAddEditEvents.Division = Convert.ToString(grdEvents.SelectedRows [0] .Cells [2] .Value);
frmAddEditEvents.Genre = Convert.ToString(grdEvents.SelectedRows [0] .Cells [3] .Value);
frmAddEditEvents.Event = Convert.ToString(grdEvents.SelectedRows [0] .Cells [4] .Value);
frmAddEditEvents.Scoreeve = Convert.ToString(grdEvents.SelectedRows [0] .Cells [5] .Value);
frmAddEditEvents.Relay = Convert.ToString(grdEvents.SelectedRows [0] .Cells [6] .Value);
frmAddEditEvents.Rounds = Convert.ToInt16(grdEvents.SelectedRows [0] .Cells [7] .Value);
frmAddEditEvents.Scoreteam = Convert.ToInt16(grdEvents.SelectedRows [0] .Cells [8] .Value);
frmAddEditEvents.timeprecison = Convert.ToInt16(grdEvents.SelectedRows [0] .Cells [9] .Value);
frmAddEditEvents.Note = Convert.ToString(grdEvents.SelectedRows [0] .Cells [10] .Value);
frmAddEditEvents.Advancement = Convert.ToInt16(grdEvents.SelectedRows [0] .Cells [11] .Value);
frmAddEditEvents obj =新的frmAddEditEvents();
obj.ShowDialog();

返回;


}
其他
{
MessageBox.Show(请选择要更新的任何记录");
}

}

how to get datagridview selected row value to textbox,radiobutton and dropdownlist which is in another windows form c# for up date

getting this error(Object reference not set to an instance of an object.)


this is my form1 code
--------------------------
public static string Gender, Division, Genre, Event, Scoreeve, Relay,Note,Selectmode;
public static int Rounds, Scoreteam, timeprecison, Advancement




public frmAddEditEvents()
{
if (Selectmode == "update")
fillRecord();
if (Selectmode == "insert")
InitializeComponent();


}


public void fillRecord()
{



rdbMale.Text = Gender;
cmbDivison.Text = Division;
rdbRun.Text = Genre;
cmbEvent.Text = Event;
chkScore.Text = Scoreeve;
chkRelay.Text = Relay;
nudRounds.Value = Rounds;
nudScores.Value = Scoreteam;
nudTimeprecision.Value = timeprecison;
txtEventnote.Text = Note;
numericUpDown1.Value = Advancement;
btnSave.Text = "update";
}

this is form 2
-------------------------


private void tsbtnEdit_Click(object sender, EventArgs e)
{


if (grdEvents.SelectedRows.Count > 0)
{



frmAddEditEvents.Selectmode = "update";

frmAddEditEvents.Gender = Convert.ToString(grdEvents.SelectedRows[0].Cells[1].Value);

frmAddEditEvents.Division = Convert.ToString(grdEvents.SelectedRows[0].Cells[2].Value);
frmAddEditEvents.Genre = Convert.ToString(grdEvents.SelectedRows[0].Cells[3].Value);
frmAddEditEvents.Event = Convert.ToString(grdEvents.SelectedRows[0].Cells[4].Value);
frmAddEditEvents.Scoreeve = Convert.ToString(grdEvents.SelectedRows[0].Cells[5].Value);
frmAddEditEvents.Relay = Convert.ToString(grdEvents.SelectedRows[0].Cells[6].Value);
frmAddEditEvents.Rounds = Convert.ToInt16(grdEvents.SelectedRows[0].Cells[7].Value);
frmAddEditEvents.Scoreteam = Convert.ToInt16(grdEvents.SelectedRows[0].Cells[8].Value);
frmAddEditEvents.timeprecison = Convert.ToInt16(grdEvents.SelectedRows[0].Cells[9].Value);
frmAddEditEvents.Note = Convert.ToString(grdEvents.SelectedRows[0].Cells[10].Value);
frmAddEditEvents.Advancement = Convert.ToInt16(grdEvents.SelectedRows[0].Cells[11].Value);
frmAddEditEvents obj = new frmAddEditEvents();
obj.ShowDialog();

return;


}
else
{
MessageBox.Show("Please select any record to update");
}

}

推荐答案

您的所有控件都可访问另一个页面吗?我认为不是,因为默认情况下所有控件都是私有的.因此您需要将所有控件的属性设置为public,然后尝试访问它.

希望它能工作.
Are your all controls accessable to another page? I think not, becouse all controls are private by default. so you need to set the properties of your all controls as public then try to access it.

hope it will work.


这篇关于如何获取datagridview选定的行值到另一个Windows窗体C#中的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆