我遇到以下代码问题.当我使用调试器时,我遇到以下行的异常:
dgvCalls.Columns.Insert(1, msisnnColumn);
Run Code Online (Sandbox Code Playgroud)
我得到一个例外:
无法添加列,因为其CellType属性为null.
奇怪的是,我为其他一些DataGridViews创建了相同的程序,它运行正常.
if (!(dgvCalls.Columns.Contains("DirectionImage")))
{
directionIconColumn = new DataGridViewImageColumn();
directionIconColumn.Name = "DirectionImage";
directionIconColumn.HeaderText = "";
dgvCalls.Columns.Insert(0, directionIconColumn);
directionIconColumn.CellTemplate = new DataGridViewImageCell();
}
if (!(dgvCalls.Columns.Contains("msisndColumn")))
{
msisnnColumn = new DataGridViewColumn();
msisnnColumn.Name = "msisndColumn";
msisnnColumn.HeaderText = "Klic";
dgvCalls.Columns.Insert(1, msisnnColumn);
msisnnColumn.CellTemplate = new DataGridViewTextBoxCell();
}
Run Code Online (Sandbox Code Playgroud)
有什么建议?
我试图将a数据绑定DataGridView到包含具有以下结构的类的列表:
MyClass.SubClass.Property
Run Code Online (Sandbox Code Playgroud)
当我单步执行代码时,SubClass永远不会请求.
我没有得到任何错误,只是没有看到任何数据.
请注意,我可以在具有相同层次结构的编辑表单中进行数据绑定.
我有DataGridView(持有任何DataBase)
我想在任何Cell中插入任何值(并且该值将保存在DataBase上)
怎么做(在C#中)
提前致谢
我一直在努力处理NullReferenceException并希望有人能指出我正确的方向.我正在尝试创建并填充DataTable,然后在DataGridView控件中显示结果.接下来是基本代码,Execution在我调用新的UpdateResults_Delegate时停止并显示NullReferenceException.奇怪的是,我可以在从QueryEventEntries返回之前成功跟踪entries.Rows.Count,所以我至少可以显示1)条目不是空引用,2)DataTable包含数据行.我知道我必须做错事,但我不知道是什么.
private void UpdateResults(DataTable entries)
{
dataGridView.DataSource = entries;
}
private void button_Click(object sender, EventArgs e)
{
PerformQuery();
}
private void PerformQuery()
{
DateTime start = new DateTime(dateTimePicker1.Value.Year,
dateTimePicker1.Value.Month,
dateTimePicker1.Value.Day,
0, 0, 0);
DateTime stop = new DateTime(dateTimePicker2.Value.Year,
dateTimePicker2.Value.Month,
dateTimePicker2.Value.Day,
0, 0, 0);
DataTable entries = QueryEventEntries(start, stop);
UpdateResults(entries);
}
private DataTable QueryEventEntries(DateTime start, DateTime stop)
{
DataTable entries = new DataTable();
entries.Columns.AddRange(new DataColumn[] {
new DataColumn("event_type", typeof(Int32)),
new DataColumn("event_time", typeof(DateTime)),
new DataColumn("event_detail", typeof(String))});
using (SqlConnection conn = new SqlConnection(DSN)) …Run Code Online (Sandbox Code Playgroud) 我有一个DataGridView.我将其.DataSource prop设置为我自己对象的BindingList:aBindingList<IChessItem>
然后我为它创建了一些列..
DataGridViewTextBoxColumn descColumn = new DataGridViewTextBoxColumn();
descColumn.DataPropertyName = "Description";
descColumn.HeaderText = "Description";
descColumn.Width = 300;
DataGridViewTextBoxColumn gameIDColumn = new DataGridViewTextBoxColumn();
gameIDColumn.DataPropertyName = "GameID";
gameIDColumn.HeaderText = "Game ID";
gameIDColumn.Width = 60;
dataGrid.Columns.Add(descColumn);
dataGrid.Columns.Add(gameIDColumn);
Run Code Online (Sandbox Code Playgroud)
我的问题是..我想根据我BindingList的另一个字段中的数据为其中一列GREEN着色.我怎样才能做到这一点?
我真的不必显示这个字段,我只想对其中的数据进行操作..
在我的例子中,IChessItem的一个字段显示记录是否是新的,我想为datagridview中的其他字段着色以反映这一点.
将数据网格视图中的数据导出到Excel工作表时出现错误:
错误(旧格式或无效的类型库.(HRESULT异常:0x80028018(TYPE_E_INVDATAREAD)))
在这条线上:
Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
我的完整代码:
private void button1_Click(object sender, EventArgs e)
{
System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
// Creating Excel Application
Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;
// Creating new WorkBook within Excel application
Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
// Creating new Excel sheet in workbook
Microsoft.Office.Interop.Excel._Worksheet worksheet = null;
// See the Excel sheet behind the program
//Funny
app.Visible = true;
// Get the reference of first sheet. By default its …Run Code Online (Sandbox Code Playgroud) 我有未绑定的DGV,我想在DGV Leave EventHandller上删除不需要的最后一行.怎么做?.
我知道通过编程方式向dgv添加新行并设置属性AllowUserToAddRows = false.
但我的问题是:是否可以在不设置属性AllowUserToAddRows = false?的情况下删除最后一行DGV.
要么
我有a的CurrentCellChanged事件处理程序,DataGridView我希望能够从事件处理程序访问当前选定的单元格列索引.
我以前在CellClick处理程序中有代码DataGridViewCellEventArgs作为参数,所以我能够从事件args参数获取列索引,但CurrentCellChanged事件有EventArgs参数,我认为这意味着暗示没有此事件的数据.
有没有办法访问新的当前选定的单元格列索引?
我试图检查datagridview单元格的空值和空值...但我不能正确...
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if ((String)dataGridView1.Rows[i].Cells[3].Value == String.Empty)
{
MessageBox.Show(" cell is empty");
return;
}
if ((String)dataGridView1.Rows[i].Cells[3].Value == "")
{
MessageBox.Show("cell in empty");
return ;
}
}
Run Code Online (Sandbox Code Playgroud)
我甚至试过这个代码
if (String.IsNullOrEmpty(dataGridView1.Rows[i].Cells[3].Value))
{
MessageBox.Show("cell is empty");
return;
}
Run Code Online (Sandbox Code Playgroud)
谁能帮我这个...
我有一个datagridview与以下数据.
ContactType | Contact
------------------------------------
Phone | 894356458
Email | xyz@abc.com
Run Code Online (Sandbox Code Playgroud)
在这里,我需要将数据"xyz@abc.com"显示为超链接,并提供工具提示"点击发送电子邮件".数字数据"894356458"不应该有超链接.
有任何想法吗???
TIA!
c# ×10
datagridview ×10
winforms ×5
.net ×1
.net-3.5 ×1
data-binding ×1
datatable ×1
excel ×1
hyperlink ×1