我想使用C#在windows应用程序的datagridiview中显示保存记录 [英] i want to show the save record in the datagridiview in windows application using C#

查看:110
本文介绍了我想使用C#在windows应用程序的datagridiview中显示保存记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意它是windows应用程序。



运行模式屏幕如下;



课程代码组合盒子



Datagridview如下;



天sess1 sess 2 sess3 sess4

1复选框复选框复选框复选框



在数据库记录中如下;



课程代码天数sess1 sess2 sess3 sess4

REO 1复选框复选复选框复选框勾选复选框





然后我在运行模式中有一个名为Search的按钮单击组合框中的REO课程时的按钮,在datagridview中显示要在datagridview中显示的特定课程详细信息。





For搜索按钮代码如下;

Note it is windows application.

Run mode screen as follows;

Course Code Combo box

Datagridview as follows;

Days sess1 sess 2 sess3 sess4
1 checkbox checkbox checkbox checkbox

In Database record as follows;

course Code Days sess1 sess2 sess3 sess4
REO 1 checkboxchecked checkboxchecked checkboxchecked checkboxchecked


Then i have one button in the run mode called Search Button when click the REO Course in the combo box, in the datagridview that particular course details to be displayed in the datagridview.


For that search button code as follows;

int irow;
sql = "select [Days],[sess1],[sess2],[sess3],[sess14] from Tb_Session_Structure where Cmn_Minor_code = '" + cb_Course_Code.Text.ToString() + "'";

dr = GFun.ReadAcessSql(sql);
while (dr.Read())
{
    for (irow = 0; irow < DGv_Session.RowCount; irow++)
    {
        DGv_Session.Rows[irow].Cells[0]  = dr[0].ToString().Trim();
        DGv_Session.Rows[irow].Cells[1] = dr[1].ToString().Trim();
        DGv_Session.Rows[irow].Cells[2] = dr[2].ToString().Trim();
        DGv_Session.Rows[irow].Cells[3] = dr[3].ToString().Trim();
        dr.Close();
    }
}





当我点击搜索按钮错误显示如下;



无法将类型字符串隐式转换为System.Windows.Forms.DataGridViewCell



我上面的代码中出现了什么问题。 />
在搜索按钮中我犯了什么错误。



请帮帮我。



问候,



Narasiman P.



when i click the Search button error shows as follows;

Cannot implicitly convert type string to System.Windows.Forms.DataGridViewCell

what is the problem in my above code.
in the search button what is the mistake i made.

please help me.

Regards,

Narasiman P.

推荐答案



write
<br />
DGv_Session.Rows[irow].Cells[0].Value  = dr[0].ToString().Trim();

< br $>




这样可以正常使用




this will work fine




我不喜欢介意帮你做作业,但是你应该理解它背后的概念。



说你的人,有的用勺子给你食物,下面的其中一个你认为会更好,



1)把汤匙放在你的汤匙上头?



2)用勺子把食物放在嘴里?



所以放弃了你头上的食物对你没用,是吗?



所以食物应该放在口中。



如果DGv_Session.Rows [irow] .Cells [0]是头,那将是什么口?



这是一个线索,称为价值。



问候

Jegan
Hi,
I don''t mind helping you with your homework, but you should understanad the concepts behind it.

Say your a human, and some one giving you food in spoon, which one of the below would you think is better,

1) dropping the food in the spoon on your head?
or
2)giving the food in the spoon in your mouth?

So dropping the food on you head is not going to be useful to you, is it?

so the food should be given in the mouth.

if DGv_Session.Rows[irow].Cells[0] is the head, what would be the mouth?

Here is a clue, something called "Value".

Regards
Jegan


线索出现错误信息
Quote:

无法将类型字符串隐式转换为System.Windows.Forms.DataGridViewCell

Cannot implicitly convert type string to System.Windows.Forms.DataGridViewCell



使用调试你应该确定它是抛出异常的这一行


Using debugging you should have determined that it is this line that is throwing the exception

DGv_Session.Rows[irow].Cells[0]  = dr[0].ToString().Trim();



很有趣,因为 DGv_Session.Rows [irow] .Cells [0] 是一个DataGridViewCell和

dr [0] .ToString()。Trim()是一个字符串。

你需要设置 Value 单元格中的单元格,而不是单元格本身的返回值。



请注意如何执行此操作,因为我相信这些是您尝试设置的复选框。 ..并且你不能将CheckBox值设置为字符串。


Funnily enough because DGv_Session.Rows[irow].Cells[0] is a DataGridViewCell and
dr[0].ToString().Trim() is a string.
You need to set the Value of the cell to the returned value from the database, not the cell itself.

Take care how you do this as I believe these are checkboxes you are trying to set ... and you can''t set a CheckBox value to a string either.


这篇关于我想使用C#在windows应用程序的datagridiview中显示保存记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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