在运行时,我正在添加DataGridView一个Windows窗体.最后一栏是DataGridViewImageColumn:
Dim InfoIconColumn As New DataGridViewImageColumn
MyDataGridView.Columns.Insert(MyDataGridView.Columns.Count, InfoIconColumn)
Run Code Online (Sandbox Code Playgroud)
添加以下代码将使我的信息图标(位图)显示在每个列单元格中,但不显示在列标题中:
Dim InfoIcon As New Bitmap("C:\MyPath\InfoIcon.bmp")
InfoIconColumn.Image = InfoIcon
Run Code Online (Sandbox Code Playgroud)
此外,值得注意的是,图像在细胞中"完美"显示,即它的大小正确以适合细胞.
但是,我找不到将相同图像添加到列标题单元格的方法.经过一些谷歌搜索我使用下面的代码将图像放在标题单元格中,但给我留下了两个问题:
_CellPainting事件减慢性能,即当悬停在DataGridView突出显示所选行时突出显示滞后于放置鼠标的位置.这是代码:
Private Sub MyDataGridView_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles MyDataGridView.CellPainting
Dim InfoIcon As Image = Image.FromFile("C:\MyPath\InfoIcon.bmp")
If e.RowIndex = -1 AndAlso e.ColumnIndex = MyDataGridView.Columns.Count - 1 Then
e.Paint(e.CellBounds, DataGridViewPaintParts.All And Not DataGridViewPaintParts.ContentForeground)
e.Graphics.DrawImage(InfoIcon, e.CellBounds)
e.Handled = True
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
有没有人知道解决我的问题的方法,并DataGridViewImageColumn在运行时获得一个大小,清晰的图像到标题单元?
是否有DateTimeFormatInfo格式模式将一周中的某一天转换为两个字符?例如星期二变成涂,星期三变成我们.格式字符串需要符合DateTimeFormatInfo for日期格式.
加成:
也许我正在寻找扩展DateTimeFormatInfo到包含自定义格式的解决方案?
我正在DataSet使用该ReadXML方法读取一个字符串.当我尝试它在路径错误中返回无效字符.如果我保存并在IE中打开字符串作为xml文件,它会encoding="UTF-16"在行上抛出一个错误,所以我认为这是问题的原因.
有没有一种简单的方法来解决这个问题?它不应该能够处理unicode或UTF-16吗?
任何建议将不胜感激.使用C#和.Net 4
<?xml version="1.0" encoding="UTF-8" ?>
<iCall xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Rows>
<Row>
<Code />
<Title>Test Title</Title>
</Row>
</Rows>
</iCall>
Run Code Online (Sandbox Code Playgroud) 我想创建一个具有类的类,但每次调用第一个类时,第二个类可能不同.例如:
public class ServerResponseObject
{
public string statusCode { get; set; }
public string errorCode { get; set; }
public string errorDescription { get; set; }
public Object obj { get; set; }
public ServerResponseObject(Object obje)
{
obj = obje;
}
}
public class TVChannelObject
{
public string number { get; set; }
public string title { get; set; }
public string FavoriteChannel { get; set; }
public string description { get; set; }
public string packageid { get; set; …Run Code Online (Sandbox Code Playgroud) 一年以来我一直在使用 maven 来管理我的项目的依赖项,但我最近才知道有一个 Maven Repository Manager 的概念。
我想问什么是Maven Repository Manager以及使用maven repository manager的目的是什么。
有一个动作:/ Home/GetName,并返回一个字符串"Mike",控制器和动作如:
public class HomeController : Controller
{
public string GetName()
{
return "Mike";
}
}
Run Code Online (Sandbox Code Playgroud)
如何在视图中显示此操作结果?(没有ajax更好)
在性能敏感的程序中,我试图显式调用IEquatable<T>.Equals()而不是Object.Equals(在我的情况下避免装箱).尽管我付出了最大的努力,编译器总是选择Object.Equals()- 我不明白.一个人为的例子:
class Foo : IEquatable<Foo>
{
public bool Equals(Foo f)
{
Console.WriteLine("IEquatable.Equals");
return true;
}
public override bool Equals(object f)
{
Console.WriteLine("Object.Equals");
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
同样可以设计的代码来证明这个问题:
// This calls IEquatable<Foo>
Foo f = new Foo();
f.Equals(f);
// This calls Object.Equals
IEquatable<Foo> i = new Foo();
i.Equals(i);
Run Code Online (Sandbox Code Playgroud)
此代码的输出是:
IEquatable.Equals
Object.Equals
Run Code Online (Sandbox Code Playgroud)
我阅读了Jon Skeet 关于重载的文章,但仍然没有理解这里的问题.所以我的问题是,我如何明确调用IEquatable<Foo>.Equals上面的变量i?
我在表单的事件处理程序中添加了一个DataGridViewComboBoxColumna DataGridView,Load并DataGridViewComboBoxCell在列中设置了每个的DataSource .但是,一旦显示表单,每个的DataSource DataGridViewComboBoxCell都已设置为null.这是我用来填充列及其单元格的代码:
DataGridViewComboBoxColumn comboCol;
comboCol = new DataGridViewComboBoxColumn();
comboCol.Name = "ComboCol";
comboCol.HeaderText = "Combo Column";
comboCol.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
this.dgv.Columns.Add(comboCol);
for (int i = 0; i < dgv.Rows.Count; i++)
{
// This datatable is actually populated here!
DataTable myData = PopulatedDataTable(dgv.Rows[i].Cells["info"].Value);
DataGridViewComboBoxCell DCC = new DataGridViewComboBoxCell();
DCC = (DataGridViewComboBoxCell)dgv.Rows[i].Cells["CombolCol"];
DCC.DataSource = myData;
DCC.DisplayMember = "Association"; // Association is a column in myData
DCC.ValueMember = "Association";
}
dgv.Columns["association"].Visible = false; …Run Code Online (Sandbox Code Playgroud) 我想让我的TextBlock可滚动,但我不能让它工作.也许问题在于StackPanel?
所以这是代码:
<Grid Margin="3">
<Grid.RowDefinitions>
<RowDefinition Height="152*" />
<RowDefinition Height="86*" />
<RowDefinition Height="67*" />
</Grid.RowDefinitions>
<ListBox x:Name="lstItems" Margin="3,6,3,0" ItemsSource="{Binding Source={StaticResource rssData}}"
SelectedIndex="0">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Width="20" Margin="3" Source="{Binding XPath=enclosure/@url}" />
<TextBlock Margin="3" VerticalAlignment="Center" Text="{Binding XPath=title}" FontWeight="Bold" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel Grid.Row="1" Orientation="Vertical" DataContext="{Binding ElementName=lstItems, Path=SelectedItem}" Grid.RowSpan="2">
<StackPanel.ScrollOwner>
<ScrollViewer />
</StackPanel.ScrollOwner>
<TextBlock Margin="3" FontSize="13" FontWeight="Bold" Text="{Binding XPath=title, Path=InnerText}" />
<TextBlock Margin="3" Opacity="0.72" Text="{Binding XPath=pubDate}" />
<ScrollViewer>
<TextBlock ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" Margin="3" FontStyle="Italic" Text="{Binding …Run Code Online (Sandbox Code Playgroud) 我有一个名为methods.cs包含两个方法的类.
例如method1和method2
我想打个method2电话method1
代码澄清:
public static void Method1()
{
// Method1
}
public static void Method2()
{
// Method2
}
Run Code Online (Sandbox Code Playgroud)
我想打个Method2电话Method1.我怎样才能做到这一点?