登录
首页 » C#源码 » C# DataGridView初级操作范例

C# DataGridView初级操作范例

于 2022-01-22 发布 文件大小:85.10 kB
0 211
下载积分: 2 下载次数: 1

代码说明:

这是一个C# DataGridView初级操作范例,演示了连接数据库、读取数据库、移动数据库指针到下一条、上一条记录的操作,以及将数据绑定到DataGridView控件中显示的整个过程,比较基础级的C#源码,因此希望新手参考:   private void shippersDataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)   {//如果错误发生在提交操作过程中,则在 MessageBox 中显示该错误    if (e.Exception != null && e.Context == DataGridViewDataErrorContexts.Commit)    {//测试时在Phone列中输入一个超长的字符串    MessageBox.Show(e.Exception.Message, "信息提示", MessageBoxButtons.OK);    }   }

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • C# WPF 功能打印的示例
    C# WPF 功能打印的示例,加载内容后,可在本程序中直接打印出XAML文档。   private void button2_Click(object sender, RoutedEventArgs e)   {//打印文件    PrintDialog MyDialog = new PrintDialog();    if ((MyDialog.ShowDialog() == true))    {    MyDialog.PrintVisual(this.richTextBox1 as Visual, "我的XAML打印文档");    }   }   private void button3_Click(object sender, RoutedEventArgs e)   {//保存文件    string MyFileName = "MyFile.XAML";    TextRange MyTextRange;    System.IO.FileStream MyStream;    MyTextRange = new TextRange(this.richTextBox1.Document.ContentStart, this.richTextBox1.Document.ContentEnd);    MyStream = new System.IO.FileStream(MyFileName, System.IO.FileMode.Create);    MyTextRange.Save(MyStream, DataFormats.XamlPackage);    MyStream.Close();   }
    2022-01-23 10:57:00下载
    积分:1
  • C# 自定义DataGridView控件列单元格外观
    C# 自定义DataGridView控件列单元格外观的例子源码,这里只是一个演示,教会一种方法,因此仅定制DataGridView第一列单元格外观。最好是把数据库连接好,有数据读出这样能更好的看到自定义单元格的效果,详细的实现代码请下载源码包。
    2022-08-24 18:26:07下载
    积分:1
  • C# 以阴影效果显示列表控件
    C# 以阴影效果显示ListBox列表控件,为ListBox显示列表控件增加渐变阴影效果,最终效果如图所示,阴影效果呈现向外扩散的渐变效果,实现方法简单,仅供参考。
    2022-04-02 01:34:44下载
    积分:1
  • C# 显示DataGridView控件中选定的单元格、行和列
    Visual C#显示选择的DataGridView单元格,获取DataGridView控件中选定的单元格、行和列,测试前请连接好数据库,实现此功能核心代码如下:   if (customersDataGridView.AreAllCellsSelected(true))   {    MessageBox.Show("所有单元格已经被选择!", "信息提示",MessageBoxButtons.OK);   }   else   {    System.Text.StringBuilder MyInfo =new System.Text.StringBuilder();    for (int i = 0;    i < MyCount; i++)    {    MyInfo.Append("行号: ");    MyInfo.Append(customersDataGridView.SelectedCells[i].RowIndex.ToString());    MyInfo.Append(", 列号: ");    MyInfo.Append(customersDataGridView.SelectedCells[i].ColumnIndex.ToString());    MyInfo.Append(", 单元格值: ");    MyInfo.Append(customersDataGridView.SelectedCells[i].Value.ToString());    MyInfo.Append(Environment.NewLine);    }    MyInfo.Append("一共选择了: " + MyCount.ToString()+"个单元格");    MessageBox.Show(MyInfo.ToString(), "信息提示", MessageBoxButtons.OK);   }
    2022-03-18 13:11:05下载
    积分:1
  • C#结合数据库生成饼形图表
    C#结合数据库生成饼形图表,这种图表是常见的数据统计图表,饼形图、柱状图等使用十分广泛,本程序演示了C#从数据库中读取出数据,然后交给饼形图生成模块,加载数据生成饼形图表。   //清空背景色   g.Clear(Color.White);   Pen pen1 = new Pen(Color.Red);   Brush brush1 = new SolidBrush(Color.PowderBlue);   Brush brush2 = new SolidBrush(Color.Blue);   Brush brush3 = new SolidBrush(Color.Wheat);   Brush brush4 = new SolidBrush(Color.Orange);   Font font1 = new Font("Courier New", 16, FontStyle.Bold);   Font font2 = new Font("Courier New", 8);   g.FillRectangle(brush1, 0, 0, width, height); //绘制背景图   g.DrawString("公司员工年龄比例饼形图", font1, brush2, new Point(80, 20)); //书写标题   int piex = 100, piey = 60, piew = 200, pieh = 200;   //20-25岁员工在圆中分配的角度   float angle1 = Convert.ToSingle((360 / Convert.ToSingle(Sum)) * Convert.ToSingle(man20to25));   //26-30岁员工在圆中分配的角度   float angle2 = Convert.ToSingle((360 / Convert.ToSingle(Sum)) * Convert.ToSingle(man26to30));   //31-40岁员工在圆中分配的角度   float angle3 = Convert.ToSingle((360 / Convert.ToSingle(Sum)) * Convert.ToSingle(man31to40));   g.FillPie(brush2
    2022-04-12 00:35:45下载
    积分:1
  • C# 确定字符串末尾是否匹配指定子串
    C# 确定字符串末尾是否匹配指定子串,本字符串查询实例具体到只匹配字符串开头和结尾是否有指定的字符串,下面是具体的查询代码编写方法:   private void button1_Click(object sender, EventArgs e)   {//确定字符串开头是否匹配指定子串    string MyFullInfo = "中华人民共和国";    string MyPartInfo="中华";    if(MyFullInfo.StartsWith(MyPartInfo))    MessageBox.Show(MyFullInfo + " 的开头是 " + MyPartInfo, "信息提示", MessageBoxButtons.OK);    else    MessageBox.Show(MyFullInfo + " 的开头不是 " + MyPartInfo, "信息提示", MessageBoxButtons.OK);   }   private void button2_Click(object sender, EventArgs e)   {//确定字符串末尾是否匹配指定子串    string MyFullInfo = "中华人民共和国";    string MyPartInfo = "共和国";    if (MyFullInfo.EndsWith(MyPartInfo))    MessageBox.Show(MyFullInfo + " 的末尾是 " + MyPartInfo, "信息提示", MessageBoxButtons.OK);    else    MessageBox.Show(MyFullInfo + " 的末尾不是 " + MyPartInfo, "信息提示", MessageBoxButtons.OK);   }
    2022-02-09 23:32:04下载
    积分:1
  • C# 将图像控件的定义导出为XAML文件
    C# 将图像控件的定义导出为XAML文件,支持的图像文件:图像文件(JPeg,Gif,Bmp,etc,tiff,png)等。   string MyXAML= System.Windows.Markup.XamlWriter.Save(this.image1);   if (System.IO.File.Exists("MyXaml.xaml"))    System.IO.File.Delete("MyXaml.xaml");   System.IO.File.AppendAllText("MyXaml.xaml", MyXAML);   MessageBox.Show(MyXAML, "MyXaml.xaml文件的内容", MessageBoxButton.OK);
    2022-04-14 09:51:54下载
    积分:1
  • C# 实现窗体控件值与数据库字段绑定
    C# 实现窗体控件值与数据库字段绑定,DataBinding的用法例子,基本的数据库操作示例,学习MyAdapter、SqlDataAdapter、DataBindings、BindingContext等的用法,测试例子如上图所示。
    2022-03-18 00:24:48下载
    积分:1
  • C# WPF把彩色图片转换为灰度图
    C# 把彩色图片转换为灰度图,这是一个基于WPF的C#图像处理程序,图像彩色转换黑白,支持的图像文件格式为:JPeg,Gif,Bmp,etc。   程序主要实现两个功能,一是将彩色转换为索引像素格式、二是将彩色转换为黑白像素格式,对应于窗口中的按钮,可查看对应功能的演示:   将彩色转换为黑白像素格式,核心代码如下:   TransformedBitmap MyRotatedBitmapSource = new TransformedBitmap();   MyRotatedBitmapSource.BeginInit();   MyRotatedBitmapSource.Source = (System.Windows.Media.Imaging.BitmapSource)this.image1.Source;   MyRotatedBitmapSource.Transform = new RotateTransform(270);   MyRotatedBitmapSource.EndInit();   FormatConvertedBitmap MyFormatedBitmap = new FormatConvertedBitmap();   MyFormatedBitmap.BeginInit();   MyFormatedBitmap.Source = MyRotatedBitmapSource;   MyFormatedBitmap.DestinationFormat = PixelFormats.BlackWhite;   MyFormatedBitmap.EndInit();   this.image1.Source = MyFormatedBitmap;   完整源码例子请在本页下载,运行效果截图如下图示。
    2022-02-01 21:42:57下载
    积分:1
  • C#在线升级程序源码样例
    C#在线升级程序源码样例,比较简单的写法,可以借鉴一下,很实用
    2022-09-03 21:15:03下载
    积分:1
  • 696516资源总数
  • 106914会员总数
  • 0今日下载