Datagridview和Tab页面 [英] Datagridview and Tab pages
问题描述
我在winforms上有两个标签页。在tab2中,数据从数据库中的datagridview中获取。在tab1中,我有一个组合框[sales analyze],它让用户选择一个选项。我现在想要从组合框选择的tab1访问tab2,从tab2 datagrid中的数据显示区域销售信息。可能吗?我真的不知道从哪里开始。
<前lang =c#> 私人 < span class =code-keyword> void cb1_SelectedIndexChanged( object sender,EventArgs e)
{
if (cbAnalyse.SelectedIndex == cb1.FindStringExact( Sales anylse))
{
}
}
tab1 image
[ ^ ]
tab2 image
[ ^ ]
示例:
在我的DVG列sales13中,北方的值是2x 800.因此tab1中北方的txtBox应显示1600等等。
EXPECTION:
1.在组合框中选择一个选项
2.使用where函数通过DGV或者???
3在相应的文本框字段中显示结果
在我的示例中我添加了2个选项卡。在第二个选项卡中添加了datagridview并在第一个选项卡文本框中。在tabindex更改后,您将在文本框中获取数据。代码如下:
private void Form1_Load( object sender,EventArgs e)
{
dataGridView1.Columns.Add( col1, 测试跨度>);
dataGridView1.Columns.Add( Col2, 结果);
string [] newstring = new string [] { North, 333};
dataGridView1.Rows.Add(newstring);
newstring = new string [] { East, 444};
dataGridView1.Rows.Add(newstring);
newstring = new string [] { Northeast, 555};
dataGridView1.Rows.Add(newstring);
}
private void tabControl1_SelectedIndexChanged(< span class =code-keyword> object sender,EventArgs e)
{
foreach (DataGridViewRow dr dataGridView1.Rows)
{
if (dr.Cells [ 0 ]。值!= null )
{
if (dr.Cells [ 0 ]。Value.ToString()== North)
{
textBox1.Text = dr.Cells [ 1 ] Value.ToString();
}
}
}
}
}
I have two tab pages on winforms. In tab2 data is fetched in a datagridview from a database. In tab1, I've a combobox [sales analyse]which makes a user to select an option. I now want to get access to tab2 from tab1 on combobox selection, displaying me a regional sales information from the data in tab2 datagrid. Is it possible? I don't really know where to start.
private void cb1_SelectedIndexChanged(object sender, EventArgs e)
{
if (cbAnalyse.SelectedIndex == cb1.FindStringExact("Sales anylse"))
{
}
}
tab1 image
[^]
tab2 image
[^]
ExAMPLE:
In my DVG in the column sales13, the values for north are 2x 800. So the txtBox for north in tab1 should display 1600 and so for the rest.
EXPECTION:
1. Select an option in combobox
2. Go through the DGV using a where function or ???
3. Display results in the appropriate textbox fields
in my example i have added 2 tabs . in 2nd tab added datagridview and in first tab text box. after tabindex change you will get data in text box. code is given below
private void Form1_Load(object sender, EventArgs e) { dataGridView1.Columns.Add("col1", "Test"); dataGridView1.Columns.Add("Col2","Result"); string[] newstring=new string[]{"North","333"}; dataGridView1.Rows.Add(newstring); newstring = new string[] { "East", "444" }; dataGridView1.Rows.Add(newstring); newstring = new string[] { "Northeast", "555" }; dataGridView1.Rows.Add(newstring); } private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { foreach (DataGridViewRow dr in dataGridView1.Rows) { if (dr.Cells[0].Value != null) { if (dr.Cells[0].Value.ToString() == "North") { textBox1.Text = dr.Cells[1].Value.ToString(); } } } } }
这篇关于Datagridview和Tab页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!